我試圖找回從谷歌分析我們的內容的實驗數據...谷歌Analytics(分析)API返回401示例代碼
我使用下面的代碼,我creds都不錯,並已審查了這帖子...
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
session_start();
$client = new Google_Client();
$client->setApplicationName('Hello Analytics API Sample');
// Visit https://cloud.google.com/console to generate your
// client id, client secret, and to register your redirect uri.
$client->setDeveloperKey('xxxxx');
$service = new Google_Service_Analytics($client);
try {
$results = $service->management_experiments->listManagementExperiments('xxxx', 'xxxx', 'xxxx');
} catch (apiServiceException $e) {
print 'There was an Analytics API service error ' . $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
print 'There was a general API error ' . $e->getCode() . ':' . $e->getMessage();
}
echo '<pre>';
print_r($results);
echo '</pre>';
我用下面的例子....
https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtExperimentsGuide#list
爲什麼我得到一個401的任何想法未經授權?需要登錄嗎?
您如何獲得授權?您是否嘗試使用繞過登錄的服務帳戶?看起來您的代碼需要通過Google進行登錄。 –
有沒有機會提供一些示例代碼?我一直在這一整天.. = [ –
那麼,你是否嘗試使用繞過登錄或代碼,需要通過谷歌登錄的服務帳戶? –