403 Google Analytics的禁止错误

时间:2012-08-27 11:40:16

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

问题说明

我正在使用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)但我无法获得解决方案。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

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

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

google api console