Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Sample PHP code for youtube.channels.list
  5. * See instructions for running these code samples locally:
  6. * https://developers.google.com/explorer-help/guides/code_samples#php
  7. */
  8.  
  9. if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
  10. throw new Exception(sprintf('Please run "composer require google/apiclient:~2.0" in "%s"', __DIR__));
  11. }
  12. require_once __DIR__ . '/vendor/autoload.php';
  13.  
  14. $client = new Google_Client();
  15. $client->setApplicationName('API code samples');
  16. $client->setScopes([
  17. 'https://www.googleapis.com/auth/youtube.readonly',
  18. ]);
  19.  
  20. // TODO: For this request to work, you must replace
  21. // "YOUR_CLIENT_SECRET_FILE.json" with a pointer to your
  22. // client_secret.json file. For more information, see
  23. // https://cloud.google.com/iam/docs/creating-managing-service-account-keys
  24. $client->setAuthConfig('YOUR_CLIENT_SECRET_FILE.json');
  25. $client->setAccessType('offline');
  26.  
  27. // Request authorization from the user.
  28. $authUrl = $client->createAuthUrl();
  29. printf("Open this link in your browser:\n%s\n", $authUrl);
  30. print('Enter verification code: ');
  31. $authCode = trim(fgets(STDIN));
  32.  
  33. // Exchange authorization code for an access token.
  34. $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
  35. $client->setAccessToken($accessToken);
  36.  
  37. // Define service object for making API requests.
  38. $service = new Google_Service_YouTube($client);
  39.  
  40. $queryParams = [
  41. 'forUsername' => 'aMOODIEsqueezie'
  42. ];
  43.  
  44. $response = $service->channels->listChannels('brandingSettings', $queryParams);
  45. print_r($response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement