【问题标题】:OAuth2 authentication for Google API with PHP使用 PHP 对 Google API 进行 OAuth2 身份验证
【发布时间】:2013-07-19 02:31:50
【问题描述】:

我需要为一家营销公司编写一个网络应用程序,该公司需要连接到他们的客户网站以访问 Google 分析数据并将其存储在他们的数据库中。 我按照 Google 在以下位置提供的示例进行操作: https://developers.google.com/analytics/solutions/articles/hello-analytics-api 我在 Google API 控制台创建了以下客户端 ID

Client ID:      915242733409.apps.googleusercontent.com
Email address:  915242733409@developer.gserviceaccount.com
Client secret:  xxx
Redirect URIs:  http://thefridgedoors.net/google-analytics/google-api-php-client/examples/analytics/simple.php
JavaScript origins: https://www.thefridgedoors.net

我的应用的身份验证如下:

/* Start a session to persist credentials */
session_start();

/* Create and configure a new client object */
$client = new Google_Client();
$client->setApplicationName("Google+ PHP Starter Application");
// Visit https://code.google.com/apis/console to generate your
// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
$client->setClientId('915242733409.apps.googleusercontent.com');
$client->setClientSecret('…');
$client->setRedirectUri('http://thefridgedoors.net/google-analytics/example1.php');
$client->setDeveloperKey('…');
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));

但是我收到以下错误: 出现一般错误:

Error calling GET https://www.googleapis.com/analytics/v3/management/accounts?key=AIzaSyALRCwV32b8fAtcvFuaDVwNUxrYrtg51tI: (403) Access Not Configured

有什么可能出错的提示吗?

【问题讨论】:

  • 您应该重置您在此处发布的 API 密钥。我已将它们从您的帖子中删除,但它们可能在我到达这里之前已被盗,并且具有足够知识的 SO 用户仍然可以查看它们。

标签: google-analytics google-api-php-client


【解决方案1】:

您需要在Google APIs Console 中为您的项目启用 Analytics API。打开您的项目,选择 Services 标签,然后点击 Analytics API 的 Status 列下的开关。

附:您可能希望避免公开您的客户机密。

【讨论】:

    猜你喜欢
    • 2013-06-24
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2022-11-03
    • 2014-04-29
    • 1970-01-01
    相关资源
    最近更新 更多