简体   繁体   English

Google Analytics(分析)Api错误(403)访问未配置

[英]Google Analytics Api Error (403) Access Not Configured

I'm trying to get the Google Analytics API to work and have started with the basic tutorial from Google in PHP . 我正在努力让Google AnalyticsAPI工作,并开始使用Google基本教程PHP

For some reason, I keep getting the following error message: 出于某种原因,我不断收到以下错误消息:

Error calling GET https://www.googleapis.com/analytics/v3/management/accounts?key=my_developer_key_from_the_console : (403) Access Not Configured 调用GET时出错https://www.googleapis.com/analytics/v3/management/accounts?key=my_developer_key_from_the_console :( 403)访问未配置

I couldn't find any solution to this, mainly because I believe I've set everything up correctly: 我找不到任何解决方案,主要是因为我相信我已经正确设置了一切:

  • The Analytics API is turned “on” in my Google Console Google Analytics中已启用Analytics API
  • OAuth2 works fine. OAuth2工作正常。 I receive an access token. 我收到了一个访问令牌。
  • My quota hasn't been reached - not even close. 我的配额尚未达到 - 甚至没有达到。

What am I missing? 我错过了什么?

You dont pass the key from apis console to 你没有把密钥从apis控制台传递给

https://www.googleapis.com/analytics/v3/management/accounts?

you should be passing the access token that you got from oauth. 你应该传递你从oauth获得的访问令牌。

https://www.googleapis.com/analytics/v3/management/accounts?oauth_token={yourtoken}

我得到了同样的错误,我通过从谷歌控制台启用Google plus api来修复它。

I had this problem too. 我也有这个问题。 Interestingly, if you don't use the client library and simply use a cURL request instead with your access_token appended, it works and JSON is returned. 有趣的是,如果您不使用客户端库并仅使用cURL请求而不是附加了access_token,则可以正常工作并返回JSON。

At least by using cURL you can be sure if it really is your configuration, or its something that the client library is doing. 至少通过使用cURL,您可以确定它是否真的是您的配置,或者它是客户端库正在执行的操作。

$url = 'https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles';
// json decode as array
$analytics_auth = json_decode($_SESSION['access_code'], true);

$ch = curl_init($url . '?access_token=' . $analytics_auth['access_token']);
curl_exec($ch);
curl_close($ch);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM