1
我一直在网站管理员工具API中遇到问题。我试图让脚本没有用户交互并获取我需要的信息。我已经使用Google Analytics(分析)处理服务帐户,但这不适用于网站管理员工具。网站管理员工具API
我目前正试图但是使用一个API服务器密钥,当我尝试查询返回的API:
码403: “用户不具备现场足够的权限”
不过我我想要查询的网站的所有者。我已经检查了www.google.com/webmasters/tools/home并且该网站已通过验证。
所以我问的是我的代码是否正确?
$KEY_FILE_LOCATION = "privateKey.json";
$viewID = "view id"; //Website View ID - including ga:
$scopes = array(
"https://www.googleapis.com/auth/analytics.readonly",
"https://www.googleapis.com/auth/webmasters.readonly"
);
$emailAddr = 'Email'; //Got off google developer console
$apiKey = 'API Server Key'; //Got off google developer console
//Create Google Client
$client = new Google_Client();
$client->setApplicationName('Logging in Attempt');
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes($scopes);
$client->setAccessType('offline');
$client->setDeveloperKey($apiKey);
//Creating Webmaster Service
$webmastersService = new Google_Service_Webmasters($client);
//Creating Request
$request = new Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$request->setStartDate('2016-07-01');
$request->setEndDate('2016-07-10');
$request->setDimensions(array('query'));
$requestWebsite = 'Website'; //The website I have access to
//Querying Webmaster
$qsearch = $webmastersService->searchanalytics->query($requestWebsite, $request);
$rows = $qsearch->getRows();
echo "<pre>",print_r($rows),"</pre>";
是否http://stackoverflow.com/questions/28080416/webmasters-api-user-does-not-have-sufficient-permission-for-site解决您的问题? – Gordon
我已经试过了,电子邮件关闭谷歌开发者控制台添加到其中的观点是财产。 – MrHappySandwich