我正在使用OAuth2服务器到服务器。
我收到此消息:
HTTP状态:403
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
我启用了所有Youtube API。
这是我的代码:
$service_token_arr = json_decode($_SESSION['service_token'], true);
$access_token = $service_token_arr['access_token'];
$url = 'https://www.googleapis.com/youtube/analytics/v1/reports';
$params = '?end-date=2015-09-10&ids=channel%3D%3D' . YOUTUBE_CHANNEL_ID . '&metrics=views&start-date=2015-05-01&dimensions=day&sort=day';
$ch = curl_init( $url . $params );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $access_token));
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
//curl_setopt($ch, CURLOPT_TIMEOUT, 40);
//execute post
$result = curl_exec( $ch );
$http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
if($http_code != '200') {
//error_log( get_bloginfo('name') . ' - Facebook Page - HTTP ' . $http_code . ' Error.' );
echo '[Error:' . $http_code . ']';
}
以下是我使用的范围:
$scopes = 'https://www.googleapis.com/auth/yt-analytics.readonly';
我使用的是PHP CURL,因为Google PHP SDK不支持Youtube Analytics。
我忘了还指出在一个帐户下我有多个Youtube帐户。我不确定如何使它与API一起使用。但我怀疑这与我的问题有关。
我有什么遗失的东西吗?
我每天只想查看我的视频观看次数。