0
votes

i have a problem getting a list of my uploded youtube videos, i think im following the documentation corectly but i always get the error "Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/youtube/v3/videos?part=contentDetails&chart=mostPopular: (403) Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."

below is my code

$OAUTH2_CLIENT_ID = 'myclientid';
        $OAUTH2_CLIENT_SECRET = 'myclientsecret';


        $client = new Google_Client();
        $client->setClientId($OAUTH2_CLIENT_ID);
        $client->setClientSecret($OAUTH2_CLIENT_SECRET);


        $client->setScopes('https://www.googleapis.com/auth/youtube');
        $redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
                FILTER_SANITIZE_URL);
        $client->setRedirectUri($redirect);




        // Define an object that will be used to make all API requests.
        $youtube = new Google_Service_YouTube($client);


        $m = $youtube->videos->listVideos('contentDetails', ['chart' => 'mostPopular','mine' => true]);




var_dump($m->items());
2

2 Answers

1
votes

As the error says: "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."

You need to sign up and get an Youtube Data API Key.

See this page for information on how to optain a authorization: https://developers.google.com/youtube/registering_an_application

Using a valid api token the given request works: Request URI: https://www.googleapis.com/youtube/v3/videos?part=contentDetails&chart=mostPopular&key=my-working-api-key

Response:

 {
     "kind": "youtube#videoListResponse",
     "etag": "\"VWxPoEGGsFABuqUjd074WYFuSzg/nDAVTxNMgQ9F4nGTs7fZaznFTOk\"",
     "nextPageToken": "CAUQAA",
     "pageInfo": {
      "totalResults": 200,
      "resultsPerPage": 5
     },
     "items": [
      {
       "kind": "youtube#video",
       "etag": "\"VWxPoEGGsFABuqUjd074WYFuSzg/_msWCTIjlV0IjeLHHznnkaF88sE\"",
       "id": "oZRh6J9ezfw",
       "contentDetails": {
        "duration": "PT5M43S",
        "dimension": "2d",
        "definition": "hd",
        "caption": "false",
        "licensedContent": true,
        "regionRestriction": {
         "blocked": [
          "ZW",
          "ZM",
        ...
0
votes

Solved it. the problem as i mentioned on my last comment was the referees. i restricted it to my website but that didnt work as it kept saying "access not configured!". but now removed the restriction and allowed all referees IT WORKS :).

might not be as secure now, but since its only me who have the developer key i think it will be fine.