我收到了分析代碼的工作方式,以便管理查詢Google Analytics並返回結果,但是當我嘗試使用代碼查詢網站站長工具時,它返回的權限不足。谷歌分析網站管理員工具權限不足
谷歌啓用API的是:分析API,谷歌搜索API控制檯
有什麼我失蹤?
谷歌Analytics(分析)代碼:
$client = new Google_Client();
$client->setAuthConfigFile($SECRET);
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY); //For analytics stuff
$client->setAccessType('offline');
$client->setPrompt('prompt');
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
//Checking to see if the token is expired
if($client->isAccessTokenExpired()){
$client->refreshToken($refreshToken);
$_SESSION['access_token'] = $client->getAccessToken();
}
$results = $analytics->data_ga->get(
$viewID,
$fromDate,
$toDate,
$metrics,
$optParams);
foreach($results->rows as $data){
echo "<pre>",print_r($data),"</pre>";
}
}else {
$redirect_uri = $redirectURL;
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
網站管理員工具代碼:
$client = new Google_Client();
$client->setAuthConfigFile($SECRET);
$client->addScope(Google_Service_Webmasters::WEBMASTERS_READONLY); //For WebMaster Tools
$client->setAccessType('offline');
$client->setPrompt('prompt');
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
//Checking to see if the token is expired
if($client->isAccessTokenExpired()){
$client->refreshToken($refreshToken);
$_SESSION['access_token'] = $client->getAccessToken();
}
//Creating Webmaster Service
$webmastersService = new Google_Service_Webmasters($client);
$searchanalytics = $webmastersService->searchanalytics;
//Creating Request
$request = new Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$request->setStartDate('2016-05-01');
$request->setEndDate('2016-05-31');
$request->setDimensions(array('query'));
$qsearch = $searchanalytics->query("http://www.example.co.uk", $request);
$rows = $qsearch->getRows();
echo "<pre>",print_r($rows),"</pre>";
} else {
$redirect_uri = $redirectURL;
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
網站管理員工具錯誤信息:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
是webmater工具auth工作請求訪問嗎? – DaImTo
它沒有請求授權,因爲我使用與分析相同的代碼,我不認爲我需要再次授權。它返回錯誤:「代碼」:403, 「消息」:「權限不足」 – MrHappySandwich
這是一種情況,我需要使用新的已啓用API刪除訪問和請求訪問? – MrHappySandwich