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

当我尝试从Google Analytics获取数据时,我收到了错误消息

Error refreshing the OAuth2 token,message: ‘{ “error” :
“unauthorized_client”,“error_description” : “Unauthorized client or
scope in request.” }’

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

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

您缺少最后一步,即可在您域的控制面板中访问您的应用程序.

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

您创建了服务帐户,现在需要委派​​/授权该应用程序.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...