1

这是一段漫长的旅程。

我到处研究过。找到解决方案一直很痛苦。

我打算做一些事情,据说很简单。我需要显示保存在 AdSense 中的报告,用户可以根据选择的时间间隔搜索结果。

事实证明,要获得此信息需要授权。当然,用户无权访问 AdSense。

我现在已经尝试过这些资源:链接链接

我遵守了规则和指导方针。

我的代码如下:

require_once 'google-api-php-client-2.2.2/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json'); //WITH REAL PATH
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/adsense.readonly');

$httpClient = $client->authorize();

// make an HTTP request
$response = $httpClient->get('https://www.googleapis.com/adsense/v1.4/accounts/pub-00000000/reports/saved');

结果是“未经授权”、“致命错误”等。

我不是这方面的专家,我完全迷路了。我真的需要这个工作!

感谢您的关注和帮助。

4

0 回答 0