Google api 网站管理员API用户对网站没有足够的权限
我使用GoogleAPI php客户端库访问网站管理员工具数据。当我想列出网站地图时,它出现了致命错误:未捕获的异常“Google\u Service\u exception”(403)用户没有足够的网站权限。另见: 我将服务帐户电子邮件地址添加为我网站的限制用户,但错误仍然存在 最后我找到了答案:Google api 网站管理员API用户对网站没有足够的权限,google-api,google-api-php-client,google-webmaster-tools,Google Api,Google Api Php Client,Google Webmaster Tools,我使用GoogleAPI php客户端库访问网站管理员工具数据。当我想列出网站地图时,它出现了致命错误:未捕获的异常“Google\u Service\u exception”(403)用户没有足够的网站权限。另见: 我将服务帐户电子邮件地址添加为我网站的限制用户,但错误仍然存在 最后我找到了答案: 服务帐户与普通的谷歌帐户不同您不能使用它访问特定的资源,即使您为特定的地址“访问”它。有关向网站管理员API授权请求的不同方式,请参阅。服务帐户与普通谷歌帐户不同。您不能使用它来访问特定的资源,即使
服务帐户与普通的谷歌帐户不同您不能使用它访问特定的资源,即使您为特定的地址“访问”它。有关向网站管理员API授权请求的不同方式,请参阅。服务帐户与普通谷歌帐户不同。您不能使用它来访问特定的资源,即使您将特定的地址指定为“访问”它 您需要通过管理服务权限。添加您的服务帐户 whatever@developer.gserviceaccount.com
那里。对我来说,问题不是实际的权限,而是域名的传递方式。下面是我的Node.js示例,但PHP也是如此:
import {JWT} from 'google-auth-library';
const client = new JWT(
null,
'service-account.json',
null,
['https://www.googleapis.com/auth/webmasters.readonly'],
);
const res = await client.request({
url: 'https://www.googleapis.com/webmasters/v3/sites/sc-domain:yourdomain.com/searchAnalytics/query',
method: 'POST',
data: {
"startDate": "2020-04-01",
"endDate": "2020-05-01",
"dimensions": ["country", "device"]
}
});
console.log(res.data);
注意语法sc-domain:yourdomain.com。传递“yourdomain.com”将导致错误用户没有足够的权限访问站点yourdomain.com
- 确保已在搜索控制台中以用户身份添加服务帐户电子邮件: