1
我試圖創建一個Android應用程序,它在谷歌驅動器上創建一個電子表格,然後將數據保存到它。驅動器部分工作正常,但由於某種原因,當我嘗試使用我的谷歌驅動器的認證,大概電子表格API(範圍https://spreadsheets.google.com/feeds/「與電子表格api我得到」com.google.gdata.util.AuthenticationException:令牌無效「Android上的Google Spreadsheet API無效令牌
這裏是我的相關代碼
private static final String[] SCOPES = { DriveScopes.DRIVE, "https://spreadsheets.google.com/feeds/" };
credential = GoogleAccountCredential.usingOAuth2(
getApplicationContext(), Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff())
.setSelectedAccountName(googleUserName);
driveService = new com.google.api.services.drive.Drive.Builder(
transport, jsonFactory, credential)
.setApplicationName(getString(R.string.app_name))
.build();
//Calls to driveService work as expected
//But this returns the invalid token exception
SpreadSheetService service = new SpreadsheetService("AppSheetservice");
final URL SPREADSHEET_FEED_URL = new URL(
"https://spreadsheets.google.com/feeds/spreadsheets/private/full");
service.setUserToken(saleActivity.credential.getToken());
//This line throws the invalid token error
feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);