[英]Google adsense api (403) User does not have an AdSense account
嘗試解決此問題已經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致命錯誤:錯誤消息:調用GET https://www.googleapis.com/adsense/v1.4/accounts?maxResults=50時出現未捕獲的異常“ Google_Service_Exception”:(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后,您是否等待了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/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.