0
我使用谷歌分析管理API 2.4獲取分析數據。 當我收到以下錯誤
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"
我得到了一些谷歌團體討論版,與我的問題(link1,link2和link3),但我不能得到解決方案
我該如何解決這個問題?
我登錄並檢查了分析服務,是在這個用戶,其實我遷移我的代碼從V2.3到V2.4在v2.3遷移到403時遷移我正在使用現有的用戶帳戶可以使用現有帳戶或我必須創建新帳戶 –
上週我開始遇到404錯誤,我正在使用的python庫。我的升級包括3部分:1)升級庫代碼,特別是URL(用新的v2.4 url替換https://www.google.com/analytics/feeds/data)。 2)更新庫身份驗證代碼以使用簡單API訪問鍵(也可在API訪問標籤下的Google API控制檯中使用)。 3)在「服務」選項卡下啓用Analytics API。這3個步驟讓我重新回到業務。聽起來就像你已經完成了步驟1和步驟3。 – klenwell
感謝您的回覆,實際上我已將數據網址更改爲https://www.googleapis.com/analytics/v2.4/data和帳戶網址,網址爲https://www.googleapis.com/analytics/v2.4 /管理/帳戶?最大結果= 1,我也設置關鍵爲DataQuery query = new DataQuery(new URL(DATA_URL)); query.setStringCustomParameter(「key」,API_KEY);我的代碼向我展示了賬戶信息,例如賬戶ID,賬戶名稱,但引發了DataFeed basicData = myService.getFeed(basicQuery,DataFeed.class)的異常。 –