这是我的代码:
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”:“请求的客户端未授权。” }''
我究竟做错了什么?