0

问题描述

我正在使用 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 群组讨论页面(链接1链接2和链接 3)但我无法获得解决方案。

我该如何解决这个问题?

4

1 回答 1

0

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

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

谷歌 API 控制台

于 2012-08-27T15:27:49.717 回答