google Api adsense(401)凭据无效

时间:2015-11-02 12:15:47

标签: adsense-api

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

  1. 我收到了报告一个频道所需的所有帐户的报告 基于渠道ID
  2. 我需要在没有谷歌的情况下为所有用户提供报告 访问我将我的详细信息保存在数据库中
  3. 我的数据:

    {
      "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)凭证无效

    我的代码:

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

1 个答案:

答案 0 :(得分:1)

执行此视频中的步骤

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);

享受:)谢谢