【问题标题】:Google adsense api (403) User does not have an AdSense accountGoogle adsense api (403) 用户没有 AdSense 帐户
【发布时间】:2019-08-28 12:03:05
【问题描述】:

尝试解决此问题已经 4 小时,它总是返回 (403) 用户没有 AdSense 帐户,我正在尝试在我的网站上获取我的 AdSense 报告, ps:是服务器到服务器的连接

    require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');
    require_once '../src/Google/Client.php';
    require_once '../src/Google/Service/AdSense.php';

    $client_email = 'xxx@xxx-1220.iam.gserviceaccount.com';
    $private_key = file_get_contents('adsense-xxxxx.p12');
    $scopes = array('https://www.googleapis.com/auth/adsense.readonly');
    $credentials = new Google_Auth_AssertionCredentials(
        $client_email,
        $scopes,
        $private_key,
    'notasecret'
    );
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_AdSense($client);

错误日志: PHP 致命错误:未捕获异常 'Google_Service_Exception' 并带有消息“调用 GET https://www.googleapis.com/adsense/v1.4/accounts?maxResults=50 时出错:(403) 用户没有 AdSense 帐户。”在 /var/www/geturl/ad/src/Google/Http/REST.php:110

#0 /var/www/geturl/ad/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /var/www/geturl/ad/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /var/www/geturl/ad/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /var/www/geturl/ad/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#5 /var/www/geturl/ad/src/Google/Service/Resource.php(240): Google_Client->execute(Object(Google_Http_Request))
#6 /var/www/geturl/ad/src/Google/Service/AdSense.php(1106): Google_Service_Resource->call('list', Array, 'Google_Servic in /var/www/geturl/ad/src/Google/Http/REST.php on line 110

【问题讨论】:

  • 看起来您没有使用正确的 api 凭据。账号下的api你开启了吗?
  • 是的,我已经在 api 控制台中启用了 adsense 管理

标签: php adsense


【解决方案1】:

您是否在启用 api 后等待了 24 小时?

尝试测试帐户以确保它在代码之外工作。使用 API 资源管理器:

https://developers.google.com/adsense/management/v1.4/reference/accounts/list#try-it

验证并尝试获取帐户列表。 如果可行,请确保您使用该帐户凭据连接到 API。

编辑:

也许其中之一可以提供帮助:

https://github.com/googleads/googleads-adsense-examples/tree/master/php-clientlib-1.x/v1.x
https://developers.google.com/adsense/management/libraries
http://www.binarytides.com/php-get-adsense-earnings-and-reports/

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多