forbidden error while fetching YouTube videos list from the YouTube API?

Viewed 1336

i am calling youtube api to get list of youtube video data. but i am getting get 403 error. i also enabled YouTube Data API (v3).

I am trying to get a list of videos from YouTube using YouTube API. I am using an API key. When I use the URL below everything works fine and I get the desired results: GET https://www.googleapis.com/youtube/v3/videos?id=i7KKDpmnR7U&key=YOUR_API_KEY=snippet,statistics,contentDetails

but when i tried locally i am unable to print the success response in my console. i always getting error response as get 403 forbidden. Is there is any issue when we run in local environment? or there is any issues with the Api

something missing any hints would be Great!

my code

$scope.youtubeApi = function(videoId){
    console.log('youtubeApi: ' + JSON.stringify(videoId));

    if (videoId) {
        //console.log('Youtube API Call function is called and Video is is : ' + videoId);

        var API_KEY = "AIzaSyCmsmxLnAnDxwQ6wzzzHnLEGBt7X8ce94wI10A";

        $http.get("https://www.googleapis.com/youtube/v3/videos?id="+ videoId + "&key=" + API_KEY + "&part=snippet,statistics,contentDetails").
        success(function (data, status, headers, config) {
           console.log('sucess call.' + JSON.stringify(data));
          //$timeout(parseresults(data), 500);
          //formObject(data);
        }).
        error(function (data, status, headers, config) {
          console.log('Error while saving this Video Id details in rest.' + JSON.stringify(data));
          console.log('Error while saving this Video Id details in rest.' + videoId);
        });
      }
  }

error on the console

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

i am getting error only when i tried to run locally using $http.get() method. but when i manually tying the url with apikey and videoId on browser window(https://www.googleapis.com/youtube/v3/videos?id=i7KKDpmnR7U&key=AIzaSyBbyrB-WGvDSYrxHhEnQfcTuiyrDkF7LwI&part=snippet,statistics,contentDetails), got success response in browser ie video object.

2 Answers
Related