So I make a request to youtube analytics that has the following scopes:
'scope' => 'https://www.googleapis.com/auth/yt-analytics.readonly https://gdata.youtube.com https://www.googleapis.com/auth/userinfo.profile'
Using my access token I try to get a list of channel subscribers from the last month, like this:
$command = 'curl -H "Authorization: Bearer ' . $access_token . '"https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DMINE&start-date=2016-07-01&end-date-2016-08-31&metrics=views&dimensions=day&sort=day';
exec($command, $result);
Even though I succeed in getting the access token and saving the user's credentials, what I get from this request is this:
array(0) { }
Without any kind of error. Does anyone have any idea why this might happen. If you require more details just ask me. I am on the clock with this problem so I really need some help fast. Any help is welcomed. Thank you all for your time! This is what I get from making a request in APIs Explorer:
{
"kind": "youtubeAnalytics#resultTable",
"columnHeaders": [
{
"name": "day",
"columnType": "DIMENSION",
"dataType": "STRING"
},
{
"name": "views",
"columnType": "METRIC",
"dataType": "INTEGER"
}
]
}
I have found the solution to my problem. In my request end-date had a typo:
end-date-2016-08-31
The correct version looks like this:
end-date=2016-08-31
And the url I was calling had to have quotation marks. So my correct call looks like this:
$command = 'curl -H "Authorization: Bearer ' . $access_token . '" "https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DMINE&start-date=' . date('Y-m-d', strtotime('-31 days')) . '&end-date=' . date('Y-m-d', strtotime('today')). '&metrics=subscribersGained%2CsubscribersLost&dimensions=day&sort=day"';
Thank you for your time!