我想从 appengine 读取特定的 Google Drive 电子表格。正在使用来自网络客户端的 Google 选择器选择电子表格。我正在尝试使用按标题查询来访问电子表格。标题被传递给我的 appengine servlet,然后我使用 Gdata Java Client Lib 进行查询。
在 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"
}
如何访问选定的电子表格?