I call youtube api to get a list of youtube videos. but I get error 403. I also included the YouTube data API (v3).
I am trying to get a list of videos from YouTube using the 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 was not able to print the success response in my console. I always get an error because you are forbidding 403. Are there any problems when starting in the local environment? or have any problems with api
something was missing any hints, it would be great!
my code
$scope.youtubeApi = function(videoId){
console.log('youtubeApi: ' + JSON.stringify(videoId));
if (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));
}).
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 console
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
I get an error only when I try to run locally using the $ http.get () method. but when I manually binds a url with apikey and videoId in the browser window ( https://www.googleapis.com/youtube/v3/videos?id=i7KKDpmnR7U&key=AIzaSyBbyrB-WGvDSYrxHhEnQfcTuiyrDkF7LwI&part=snippet,statistics,contentDetails ), I received an answer of success in your browser , i.e. video object.