【问题标题】:403 Forbidden error for Google Analytics谷歌分析的 403 禁止错误
【发布时间】:2012-08-27 11:40:15
【问题描述】:

问题描述

我正在使用 Google analytic Management API 2.4 来获取 Analytic 的数据。 我在哪里得到以下错误

com.google.gdata.util.ServiceForbiddenException: Forbidden
<?xml version="1.0" encoding="UTF-8"?><errors xmlns="http://schemas.google.com/g/2005"><error><domain>GData</domain><code>insufficientPermissions</code><internalReason>User does not have permission to perform this operation</internalReason></error></errors>
atcom.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:605)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:1077)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:676)
at com.google.gdata.client.Service.getFeed(Service.java:1034)
at com.report.pojo.GoogleAnlytics2.printFirstAccount(GoogleAnlytics2.java:80)
at com.report.pojo.GoogleAnlytics2.main(GoogleAnlytics2.java:91)

我正在使用以下代码

public static DataQuery getBasicQuery(String tableId) throws MalformedURLException {
    DataQuery query = new DataQuery(new URL(DATA_URL));
    query.setIds(tableId);
    query.setStartDate("2011-07-12");
    query.setEndDate("2012-07-15");
    query.setDimensions("ga:hour");
    query.setMetrics("ga:visits,ga:bounces");
    query.setStringCustomParameter("key",API_KEY);
    return query;
}

public static void printData(String title, DataFeed dataFeed) {
    System.out.println(title);
    System.out.println(dataFeed.getEntries().size());
    for (DataEntry entry : dataFeed.getEntries()) {
        System.out.println("\tHour: " + entry.stringValueOf("ga:hour"));
        System.out.println("\t\tVisits: " + entry.stringValueOf("ga:visits"));
        System.out.println("\t\tBounces: " + entry.stringValueOf("ga:bounces"));
        System.out.println("\t\tBounce rate: "+ entry.longValueOf("ga:bounces") / (double) entry.longValueOf("ga:visits"));
    }
    System.out.println();
}

BASE_URL="https://www.googleapis.com/analytics/v2.4/management/"
DATA_URL="https://www.googleapis.com/analytics/v2.4/data"

我有一些与我的问题相关的 Google 群组讨论页面(link1link2link3)但我无法获得解决方案。

我该如何解决这个问题?

【问题讨论】:

    标签: jakarta-ee google-analytics google-analytics-api web-analytics


    【解决方案1】:

    您是否在 Google API 控制台中启用了 Google Analytics API?上周我不得不这样做,因为我正在更新我的 python 代码。

    如果您还没有这样做,请登录https://code.google.com/apis/console/,然后将状态设置为开启:

    【讨论】:

    • 我登录并检查该用户的分析服务是否已开启,实际上我正在将我的代码从 V2.3 迁移到 V2.4,因为在迁移时我正在使用现有用户,因为 v2.3 转到了 403帐户可以使用现有帐户还是我必须创建新帐户
    • 上周我开始使用我正在使用的旧 python 库遇到 404 错误。我的升级分为 3 个部分:1) 升级库代码,特别是 url(将 google.com/analytics/feeds/data 替换为新的 v2.4 url​​)。 2) 更新库身份验证代码以使用简单 API 访问密钥(也可从 API 访问选项卡下的 Google API 控制台获得)。 3) 在服务选项卡下启用分析 API。这三个步骤让我重新开始工作。听起来您已经完成了第 1 步和第 3 步。第 2 步?
    • 感谢您的回复,实际上我已将数据 URL 更改为 googleapis.com/analytics/v2.4/data 并将帐户 URL 更改为 googleapis.com/analytics/v2.4/management/accounts?max-results=1 并且我还将密钥设置为 DataQuery query = new DataQuery(new URL(DATA_URL)) ; query.setStringCustomParameter("key",API_KEY);我的代码向我显示了一个帐户信息,例如 Account ID 、Account Name 但引发代码 DataFeed basicData = myService.getFeed(basicQuery, DataFeed.class); 的异常
    • 我只是想知道我们是否可以仅使用 API_KEY 访问数据,或者我还需要提供 Oauth 2 信息?
    • 我还没有将我的代码升级到 Oauth 2。我正在使用 Simple API 密钥(用于浏览器应用程序,IIRC)。以前我一直使用 Google 帐户用户名和密码进行身份验证。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-26
    • 2015-10-18
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    相关资源
    最近更新 更多