Error getting retrieved YouTube video list from YouTube API?

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) {
        //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 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.

+4
source share
2 answers

According to the document with the YouTube v3 error . Error type 403 is a symbol of either forbidden, or quotaExceeded. Below is a description.

enter image description here

, , id (i7KKDpmnR7U), , .

                                       OR

videos.list (403) , . .

+2

, :

var url = 'https://www.googleapis.com/youtube/v3/videos';

// These are the required query options
var requiredParameters = {
  part: 'snippet', //required, json form, use 'snippet'
  key: 'API_KEY', // required, put api key here, try to hide it
  id: '12345', // required, the video id
};


$http({
  method: 'GET',
  url: url,
  params: requiredParameters
})
.then((response) => {

})
.catch((err) => {

})


/* Optional parameters
{
  h1,
  maxHeight,
  maxResults,
  maxWidth,
  onBehalfOfContentOwner,
  pageToken,
  regionCode,
  videoCategoryId
}
*/

: , OAuth 2.0. , :

Authorization: 'Bearer oauth2-token'

- "" "access_token" OAuth 2.0

+1

Source: https://habr.com/ru/post/1681460/


All Articles