How to get the data of a video from youtube in javascript

Viewed 2386

I am trying to get the data of a video from youtube using youtube data API but I am getting the 403 forbidden error like below

{"error":{"errors":[{"domain":"global","reason":"forbidden","message":"Forbidden"}],"code":403,"message":"Forbidden"}}

What I am trying is:

      var apiKey = "xxxxxxxxxxxxxxxxxxxxx";   
        var  videoId = "s7wmiS2mSXY";

        var gUrl = "https://www.googleapis.com/youtube/v3/videos?id=" + videoId + "&key=" + apiKey + "&part=snippet,statistics,contentDetails";

$http({
        method: 'GET',
        url: gUrl
      }).then(function successCallback(response) {
        console.log('sucess call.', response);
      }, function errorCallback(err) {
        console.log('Error while saving this Video Id details in videoId.', err);
      });

While I copied the whole url https://www.googleapis.com/youtube/v3/videos?id=s7wmiS2mSXY&key=XXXXmyApiKeyXXXXX&part=snippet,statistics,contentDetails and tried in a new tab, I am getting the json object in browser but when I tried it on my localhost using $http.get I am getting the 403 forbidden error.

Thanks in advance.

1 Answers
Related