【问题标题】:Google_Auth_Exception When trying to get OAuth 2.0 Service Account AuthenticationGoogle_Auth_Exception 尝试获取 OAuth 2.0 服务帐户身份验证时
【发布时间】:2014-07-19 01:45:41
【问题描述】:

这是我的代码:

session_start(); 错误报告(E_ALL); ini_set('display_errors', 1); require_once 'Google/Client.php'; require_once 'Google/Service/AdExchangeSeller.php'; $scriptUri = "http://example.com/some_seller_api.php"; $client_id = 'XXXXXX.apps.googleusercontent.com'; $service_account_name = 'XXXXXXXXX@developer.gserviceaccount.com'; $key_file_location = '/XXXXX/privatekey.p12'; $client = new Google_Client(); $client->setApplicationName("Example_app"); if (isset($_SESSION['service_token'])) { $client->setAccessToken($_SESSION['service_token']); } $key = file_get_contents($key_file_location); $cred = 新的 Google_Auth_AssertionCredentials( $service_account_name, 数组('https://www.googleapis.com/auth/adexchange.seller.readonly'), $密钥 ); $client->setAssertionCredentials($cred); if($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $_SESSION['service_token'] = $client->getAccessToken(); $service = new Google_Service_AdExchangeSeller($client); $acc = $service->adclients->listAdclients();

我做的一切都像官方手册和https://github.com/google/google-api-php-client/blob/master/examples/service-account.php中的例子

我有一个错误:

致命错误:未捕获的异常 'Google_Auth_Exception' 带有消息“刷新 OAuth2 令牌时出错,消息:'{“error”:“access_denied”,“error_description”:“请求的客户端未授权。” }''

我做错了什么?

【问题讨论】:

    标签: php google-app-engine service-accounts


    【解决方案1】:

    您似乎没有使用目标服务授权您的应用程序。 OAuth2 步骤之一是您的应用程序(将要访问服务的应用程序)需要向目标服务“注册”(或授权)。这是您将注册什么是回调 URL 等的方式。

    根据您的代码,您正在访问 Ad Exchange Seller REST API。打开以下链接并按照分步指南来解决您遇到的问题:

    https://developers.google.com/ad-exchange/seller-rest/getting_started#auth

    【讨论】:

    • 我已经从谷歌小组得到了答案。我正在尝试使用不支持服务帐户的 AdxSeller。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2012-11-08
    • 2017-03-07
    • 1970-01-01
    • 2013-12-04
    相关资源
    最近更新 更多