Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google OAuth2.0为服务帐户使用PHP和JSON_Php_Json_Google Api_Service Accounts - Fatal编程技术网

Google OAuth2.0为服务帐户使用PHP和JSON

Google OAuth2.0为服务帐户使用PHP和JSON,php,json,google-api,service-accounts,Php,Json,Google Api,Service Accounts,我试图使用GoogleAPI示例使OAuth2.0与我的服务帐户一起工作,但是我在没有使用Google_Auth_断言Redentials的示例代码工作时遇到了问题,因为它已被弃用 该文件是通过开发者控制台中的服务帐户页面生成的JSON 下面是代码片段 // Create and configure a new client object. $client = new Google_Client(); $client->setApplicationName("myApp"); $clie

我试图使用GoogleAPI示例使OAuth2.0与我的服务帐户一起工作,但是我在没有使用Google_Auth_断言Redentials的示例代码工作时遇到了问题,因为它已被弃用

该文件是通过开发者控制台中的服务帐户页面生成的JSON

下面是代码片段

// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("myApp");

$client->setAuthConfig($key_file_location);
$client->setScopes(Google_Service_Analytics::ANALYTICS);

if($client->isAccessTokenExpired()) {
  $client->getRefreshToken();
}

$analytics = new Google_Service_Analytics($client);

提前感谢您的帮助。

我这里也有同样的问题,还没有答案。您能详细说明一下为什么要使用服务帐户吗?问题可能是库希望OAuth客户端而不是服务帐户使用JSON。嗨,Patrick,我在GA中创建了自定义维度,需要上传一个CSV文件来填充这些维度。我想使用服务帐户每月自动上传CSV。嗨,Jordi,我尝试了你的解决方案,但下载新服务帐户的JSON没有帮助。我这里也有同样的问题,还没有答案。您能详细说明一下为什么要使用服务帐户吗?问题可能是库希望OAuth客户端而不是服务帐户使用JSON。嗨,Patrick,我在GA中创建了自定义维度,需要上传一个CSV文件来填充这些维度。我想使用一个服务帐户来自动化每月上传CSV的过程。嗨,Jordi,我尝试了你的解决方案,但是下载JSON以获得一个新的服务帐户没有帮助。