首页 > 解决方案 > 使用 OAuth2.0 在 PHP 中包含 Google Sitemap Api

问题描述

在 PHP 中集成 Google Sitemap API 时,我使用 Google OAuth2.0 登录(像魅力一样工作),但此代码不适合:

$key = 'SOME-GOOGLE-KEY';
$obj = json_decode(file_get_contents("https://www.googleapis.com/webmasters/v3/sites?key=$key"), true);

print_r($obj);

错误信息:

无法打开流:HTTP 请求失败!HTTP/1.0 401 未经授权

API-key 正确无限制。它绑定到“Google Search Console API”。“Google Search Console API”也被激活。

如何正确授权?

标签: phpoauth-2.0google-api

解决方案


至少我找到了一个名为:google-api-php-client 的解决方案,它托管在 GitHub 上:

https://github.com/googleapis/google-api-php-client


推荐阅读