Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3642

Why Youtube API show code 403 quote exhausted error?

$
0
0

I am trying to use Youtube API but I am getting 403 error. I tried to query directly on the Youtube API website I have successfully queried with code 200 but not 403. I tried regenerating the credentials.json file but it still gives me a 403 error. I am using PHP 7.2.31. Thank you for your help!

This is my code:

<?phpuse Google\Service\YouTube;// define('STDIN', fopen('php://stdin', 'r'));/** * Sample PHP code for youtube.activities.list * See instructions for running these code samples locally: * https://developers.google.com/explorer-help/code-samples#php */if (!file_exists(__DIR__ . '/vendor/autoload.php')) {  throw new Exception(sprintf('Please run "composer require google/apiclient:~2.0" in "%s"', __DIR__));}require_once __DIR__ . '/vendor/autoload.php';$client = new Google_Client();$client->setApplicationName('API code samples');$client->setScopes(['https://www.googleapis.com/auth/youtube.readonly',]);// TODO: For this request to work, you must replace//       "YOUR_CLIENT_SECRET_FILE.json" with a pointer to your//       client_secret.json file. For more information, see//       https://cloud.google.com/iam/docs/creating-managing-service-account-keys$client->setAuthConfig('credentials.json');$client->setAccessType('offline');// // Request authorization from the user.// $authUrl = $client->createAuthUrl();// printf("Open this link in your browser:\n%s\n", $authUrl);// // print('Enter verification code: ');// // $authCode = trim(fgets(STDIN));// if(isset($_GET['code'])){// $authCode = $_GET['code'];// // Exchange authorization code for an access token.// $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);// var_dump($accessToken);// }$getAccessToken="This is Access Token";try {$client->setAccessToken($getAccessToken);// Define service object for making API requests.$service = new YouTube($client);$queryParams = ['maxResults' => 1,'mine' => true];    $response = $service->activities->listActivities('snippet', $queryParams);// print_r($response);} catch (\Throwable $th) {    echo "<pre>";    echo $th;}

This is the error i got

Google\Service\Exception: {"error": {"code": 403,"message": "The request cannot be completed because you have exceeded your \u003ca href=\"/youtube/v3/getting-started#quota\"\u003equota\u003c/a\u003e.","errors": [      {"message": "The request cannot be completed because you have exceeded your \u003ca href=\"/youtube/v3/getting-started#quota\"\u003equota\u003c/a\u003e.","domain": "youtube.quota","reason": "quotaExceeded"      }    ]  }} in C:\xampp\htdocs\Youtube API\Youtube API\Login\vendor\google\apiclient\src\Http\REST.php:134Stack trace:#0 C:\xampp\htdocs\Youtube API\Youtube API\Login\vendor\google\apiclient\src\Http\REST.php(107): Google\Http\REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google\\Service\\...')#1 [internal function]: Google\Http\REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google\\Service\\...')#2 C:\xampp\htdocs\Youtube API\Youtube API\Login\vendor\google\apiclient\src\Task\Runner.php(187): call_user_func_array(Array, Array)#3 C:\xampp\htdocs\Youtube API\Youtube API\Login\vendor\google\apiclient\src\Http\REST.php(66): Google\Task\Runner->run()#4 C:\xampp\htdocs\Youtube API\Youtube API\Login\vendor\google\apiclient\src\Client.php(921): Google\Http\REST::execute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google\\Service\\...', Array, NULL)#5 C:\xampp\htdocs\Youtube API\Youtube API\Login\vendor\google\apiclient\src\Service\Resource.php(238): Google\Client->execute(Object(GuzzleHttp\Psr7\Request), 'Google\\Service\\...')#6 C:\xampp\htdocs\Youtube API\Youtube API\Login\vendor\google\apiclient-services\src\YouTube\Resource\Activities.php(63): Google\Service\Resource->call('list', Array, 'Google\\Service\\...')#7 C:\xampp\htdocs\Youtube API\Youtube API\Login\test.php(55): Google\Service\YouTube\Resource\Activities->listActivities('snippet', Array)#8 {main}

Viewing all articles
Browse latest Browse all 3642

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>