google Api adsense (401) 凭据无效

google Api adsense (401) Invalid Credentials

我有一个带有自定义渠道的 AdSense 帐户,我做了所有事情,但有两个问题:

  1. 我得到所有帐户的报告 我需要得到一个频道的报告 基于频道 ID
  2. 我需要为所有用户获取报告,而他们没有我的 google 当我将我的详细信息保存在数据库中时访问

我的数据:

{
  "access_token" : "XXXX.XXXX",
  "token_type" : "XXXX",
  "expires_in" : XXXX,
  "created" : XXXX
}

我的更新语句:

$access_token_update = json_decode($access_token);
$access_token_update->created = time();

我收到此错误消息:

(401) Invalid Credentials

我的代码:

$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setAccessType('offline');
$client->setAccessToken($access_token);
$service= new Google_Service_AdSense($client);

执行此视频中的步骤

https://www.youtube.com/watch?v=hfWe1gPCnzc

保存结果示例中的代码

{
 "access_token": "XXXXXXXX", 
 "token_type": "XXXX", 
 "expires_in": XXXX, 
 "refresh_token": "XXXXXXXXX"

}

然后按以下方式更新您的文件

$access_token = "from database or file or what you want to save"; // this will be code you got by doing steps in this video.
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setAccessType('offline');
$access_token_json = json_decode($access_token);
$client->refreshToken($access_token_json ->refresh_token);
$service= new Google_Service_AdSense($client);

享受 :) 谢谢