dongshuobei1037 2018-05-14 06:16
浏览 398

Google Api,如何将访问令牌传递给API调用

I'm trying to use the Google analytics API. I created an account in the developer console, I use the OAuth2 to grant access to users data. So I have my refresh_token. But now, I would like to get all profilesID in GA for the account I have access to. I follow the Google's official tutorial and I get this error :

{
"error": {
    "errors": [{
        "domain": "global",
        "reason": "required",
        "message": "Login Required",
        "locationType": "header",
        "location": "Authorization"
    }],
    "code": 401,
    "message": "Login Required"
}

}

I see that i missed the credential but I dont know how to passe the access_token in this call. Here is my code :

$client = new Google_Client();
    $client->setApplicationName("APP_NAME");
    $client->setAuthConfig(GA_KEYS_JSON);

    $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
    $analytics = new Google_Service_Analytics($client);

    // Get the list of accounts for the authorized user.
    $accounts = $analytics->management_accounts->listManagementAccounts();
    $items = $accounts->getItems();

    var_dump($items);die();

Any idea ?

  • 写回答

4条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试