我試圖做一些分析查詢從服務器到服務器。 我正在使用laravel和https://github.com/google/google-api-php-client庫。Youtube Analytics API PHP無效查詢。查詢不符合預期
這是我使用的代碼:
$client = new Google_Client();
$key = file_get_contents(storage_path('key.p12'));
$cred = new Google_Auth_AssertionCredentials(
'***@developer.gserviceaccount.com', array('https://www.googleapis.com/auth/youtube.readonly', 'https://www.googleapis.com/auth/yt-analytics.readonly'), $key);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
Session::put('service_token', $client->getAccessToken());
$service = new Google_Service_YouTubeAnalytics($client);
$id = 'channel==MINE';
$start_date = '2014-05-01';
$end_date = '2014-06-30';
$optparams = array(
'dimensions' => 'day',
'sort' => 'day,-views'
);
$metric = 'views,estimatedMinutesWatched';
$api = $service->reports->query($id, $start_date, $end_date, $metric, $optparams);
$service = new Google_Service_YouTubeAnalytics($client);
$id = 'channel==MINE';
$start_date = '2014-05-01';
$end_date = '2014-06-30';
$optparams = array(
'dimensions' => 'day',
'sort' => 'day,-views'
);
$metric = 'views,comments,favoritesAdded,likes,dislikes,estimatedMinutesWatched,averageViewDuration';//'views,estimatedMinutesWatched';
$api = $service->reports->query($id, $start_date, $end_date, $metric, $optparams);
我的問題是,認證工作得很好,但我不能讓分析查詢得到的要努力,我發現了以下錯誤:
Error calling GET https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DMINE&start-date=2014-05-01&end-date=2014-06-30&metrics=views%2CestimatedMinutesWatched&dimensions=day&sort=day%2C-views: (400) Invalid query. Query did not conform to the expectations.
任何想法?
嗨,我有同樣的問題,我猜!你是如何修改oAuth2的? – zeidanbm 2016-01-23 20:05:57