首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >网站管理员工具API

网站管理员工具API
EN

Stack Overflow用户
提问于 2016-07-14 21:30:13
回答 0查看 462关注 0票数 1

我一直有一个网站管理员工具API的问题。我试图使脚本没有用户交互,并获得我需要的信息。我有谷歌分析服务帐户的工作,但这是不支持的网站管理员工具。

我目前正在尝试使用API服务器密钥,但是当我尝试查询它返回的API时:

代码403:“用户没有足够的权限访问网站”

然而,我是我试图查询的网站的所有者。我已经检查了www.google.com/webmaster/tools/home,该站点已通过验证。

所以我问我的代码是正确的吗?

代码语言:javascript
复制
$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>";
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38375624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档