我想從appengine中讀取特定的Google Drive電子表格。電子表格正在使用來自Web客戶端的Google picker進行挑選。我試圖通過標題查詢來訪問電子表格。標題傳遞給我的appengine servlet,然後使用Gdata Java Client Lib進行查詢。來自appengine問題的Google電子表格
AppEngine上我有這樣的代碼:
public static FeedURLFactory factory = FeedURLFactory.getDefault();
public static SpreadsheetService spreadsheetService= new SpreadsheetService("evermedcpr");
List scopes = Arrays.asList("https://spreadsheets.google.com/feeds");
AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(scopes);
Credential creds = new Credential(BearerToken.authorizationHeaderAccessMethod());
creds.setAccessToken(accessToken.getAccessToken());
SpreadsheetService ss = new SpreadsheetService("DBM4G-demo");
ss.setOAuth2Credentials(creds);
getSpreadsheet(spreadsheetName);
public SpreadsheetEntry getSpreadsheet(String spreadsheet)
throws Exception {
SpreadsheetQuery spreadsheetQuery
= new SpreadsheetQuery(new URL("https://spreadsheets.google.com/feeds/"));
spreadsheetQuery.setTitleQuery(spreadsheet);
SpreadsheetFeed spreadsheetFeed = spreadsheetService.query(spreadsheetQuery,
SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = spreadsheetFeed.getEntries();
if (spreadsheets.isEmpty()) {
throw new Exception("No spreadsheets with that name");
}
return spreadsheets.get(0);
}
}
我總是在我的日誌404響應:
com.google.api.client.googleapis.services.AbstractGoogleClient <init>: Application name is not set. Call Builder#setApplicationName.
W 2013-07-15 14:50:31.665
[s~evermedcpr/1.368807282351251748].<stderr>: An error occurred: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 OK
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"message" : "Not Found",
"reason" : "notFound"
} ],
"message" : "Not Found"
}
如何去訪問選定的試算表??
是對的OAuth位工作?如果沒有,請使用DrEdit教程讓OAuth在App Engine上工作。之後,看看CellDemo.java以瞭解如何使用API。 (注意谷歌應用程序腳本更簡單的選項,而不是電子表格API) – eddyparkinson
我想這需要有人發佈完整的解決方案。我有代碼來做到這一點,但需要花費我太多時間來提取所需的位,並進行調試等。DrEdit位非常大,需要進行一些更改。 – eddyparkinson
@eddyparkinson是oauth正在工作。我發現了這個問題。我正在使用錯誤的feedurl。將盡快更新。 – Patrick