Note that there are some explanatory texts on larger screens.

plurals
  1. POYouTube Analytics API + service access = Fatal error: Uncaught exception (500)
    primarykey
    data
    text
    <p>I am trying to get some YouTube Analytics reports using the API with a Service account in order to perform some CRON jobs. I've already solved the common problem of NTP server sync and, obviously, i've set up the API console properly. </p> <pre><code> &lt;?php ini_set('display_errors', 1); require_once 'gapi/src/Google_Client.php'; require_once 'gapi/src/contrib/Google_YouTubeAnalyticsService.php'; // Define constants. const CLIENT_ID = '************************.apps.googleusercontent.com'; const SERVICE_ACCOUNT_NAME = '************************@developer.gserviceaccount.com'; const KEY_FILE = '************************-privatekey.p12'; const MY_CHANNEL = '************************'; $client = new Google_Client(); $client-&gt;setApplicationName("YouTube Analytics API Test"); session_start(); if (isset($_SESSION['token'])) { $client-&gt;setAccessToken($_SESSION['token']); } $key = file_get_contents(KEY_FILE); $client-&gt;setAssertionCredentials(new Google_AssertionCredentials( SERVICE_ACCOUNT_NAME, array("https://www.googleapis.com/auth/yt-analytics.readonly"), $key) ); $client-&gt;setClientId(CLIENT_ID); if ($client-&gt;getAuth()-&gt;isAccessTokenExpired()) { $client-&gt;getAuth()-&gt;refreshTokenWithAssertion(); } $token = $client-&gt;getAccessToken(); $youtubeAnalyticsService = new Google_YouTubeAnalyticsService($client); $optparam = array("dimensions" =&gt; "country", "max-results" =&gt; "10"); $reports = $youtubeAnalyticsService-&gt;reports-&gt;query("channel==" . MY_CHANNEL, "2013-09-01", "2013-09-25", "views", $optparam); echo $reports; ?&gt; </code></pre> <p>returns to me this message:</p> <pre><code>Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DmychannelID&amp;start-date=2013-09-01&amp;end-date=2013-09-25&amp;metrics=views&amp;dimensions=country&amp;max-results=10: (500) Unknown error occurred on the server.' in /mydomain/gapi/src/io/Google_REST.php:66 Stack trace: 0 /mydomain/gapi/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) 1 /mydomain/gapi/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) 2 /mydomain/gapi/src/contrib/Google_YouTubeAnalyticsService.php(48): Google_ServiceResource-&gt;__call('query', Array) 3 /mydomain/myfile.php(45): Google_ReportsServiceResource-&gt;query('channel==...', '2013-09-01', '2013-09-25', 'views', Array) 4 {main} thrown in /mydomain/gapi/src/io/Google_REST.php on line 66 </code></pre> <p>Any suggestion? Thank you all in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload