2015-11-14 146 views
0

我使用下面的代码来获取统计信息我的网站从搜索控制台没有权限:php |谷歌网站管理员API服务帐户具有

$client = new Google_Client(); 
$creds = $client->loadServiceAccountJson('---JSON FILE---', 'https://www.googleapis.com/auth/webmasters.readonly'); 
$client->setAssertionCredentials($creds); 


$service = new Google_Service_Webmasters($client); 

$ressource = $service->searchanalytics; 

$options = new Google_Service_Webmasters_SearchAnalyticsQueryRequest(); 
$options->setStartDate('2015-11-11'); 
$options->setEndDate('2015-11-11'); 

try{ 
    $response = $ressource->query('http://www.example.com/', $options); 
} catch (Exception $e){ 
    echo $e->getMessage(); 
} 

我使用谷歌的服务帐户授权API调用,但它给了我错误:

Error calling POST https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fwww.example.com%2F/searchAnalytics/query : (403) User does not have sufficient permission for site 'http*://www.example.com/'. See also: https://support.google.com/webmasters/answer/2451999 .

我也将服务帐户的电子邮件地址作为所有者添加到我的搜索控制台属性,但错误仍然存​​在。我不知道了,我做错了什么?

回答