Questions tagged «google-analytics-api»


17
如何使用Google API客户端刷新令牌?
我一直在使用Google Analytics(分析)API(V3),遇到了som错误。首先,所有设置均正确无误,并且可以使用我的测试帐户。但是,当我想从另一个个人资料ID(相同的Google Accont / GA帐户)获取数据时,出现403错误。奇怪的是,某些Google Analytics(分析)帐户中的数据会返回数据,而其他帐户会生成此错误。 我已经撤消了令牌并再次进行了身份验证,现在看来我可以从所有帐户中获取数据了。问题解决了?不。由于访问密钥将过期,因此我将再次遇到相同的问题。 如果我理解正确,可以使用resfreshToken获得新的authenticationTooken。 问题是,当我运行时: $client->refreshToken(refresh_token_key) 返回以下错误: Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }' 我已经检查了refreshToken方法背后的代码,并将请求追溯到“ apiOAuth2.php”文件。所有参数均正确发送。grant_type在方法中硬编码为“ refresh_token”,因此我很难理解出了什么问题。参数数组如下所示: Array ( [client_id] => *******-uqgau8uo1l96bd09eurdub26c9ftr2io.apps.googleusercontent.com [client_secret] => ******** [refresh_token] => 1\/lov250YQTMCC9LRQbE6yMv-FiX_Offo79UXimV8kvwY [grant_type] => refresh_token ) 步骤如下。 $client = new apiClient(); $client->setClientId($config['oauth2_client_id']); $client->setClientSecret($config['oauth2_client_secret']); $client->setRedirectUri($config['oauth2_redirect_uri']); $client->setScopes('https://www.googleapis.com/auth/analytics.readonly'); $client->setState('offline'); …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.