【问题标题】:Error refreshing the OAuth2 token, message: '{ "error" : "unauthorized_client", "error_description" : "Unauthorized client or scope in request." }'刷新 OAuth2 令牌时出错,消息:'{ "error" : "unauthorized_client", "error_description" : "Unauthorized client or scope in request." }'
【发布时间】:2016-05-26 18:02:32
【问题描述】:

当我尝试从 Google Analytics 获取数据时,出现错误

刷新 OAuth2 令牌时出错,消息:'{ "error" : "unauthorized_client", "error_description" : "未经授权的客户端或 请求范围。” }'

我在 https://console.developers.google.com/project 中创建项目,创建 服务帐户 并下载 .p12 密钥。还要在项目设置中启用“Analytics API”,但它不起作用。这是我的代码:

    $service_account_name = '<Service Email>@developer.gserviceaccount.com';
    $key_file_location = '<keyName>.p12';
    $key = file_get_contents($key_file_location);
    $cred = new Google_Auth_AssertionCredentials(
        $service_account_name,
        array(Google_Service_Analytics::ANALYTICS),
        $key,
        'notasecret',
        'http://oauth.net/grant_type/jwt/1.0/bearer',
        '<My email>'
    );
$client->getAuth()->setAssertionCredentials($cred);
$service = new Google_Service_Analytics($client);
$result = $service->data_ga->get("ga:<profileID>", "yesterday", "today", "ga:pageviews");
print_r( $result);

我的项目有什么问题?请帮忙。

【问题讨论】:

  • 您是否将该项目添加到您的域中?添加clientId和范围?
  • 不,我没有。你能告诉我,我需要在哪里添加这个参数吗?
  • 有任何想法,我的项目有什么问题?

标签: php oauth-2.0 google-oauth google-analytics-api google-api-php-client


【解决方案1】:

您错过了最后一步,即在您的域的控制面板中访问您的应用程序。

https://developers.google.com/+/domains/authentication/delegation

您创建了服务帐户,现在您需要委托/授权应用程序。

【讨论】:

  • 你能解释一下吗?我正在尝试在 WordPress 网站中使用 Gmail for WP SMTP 插件来发送电子邮件。但是在执行每个步骤后,它会显示错误
  • Mailer: Gmail { "error": "unauthorized_client", "error_description": "Unauthorized" }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多