2015-07-04 19 views
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); 

回答

1

我终于想通了这个问题是你需要调用

service.setAuthSubToken(credential.getToken()); 

,而不是

service.setUserToken(credential.getToken());