【问题标题】:Google Spreadsheet API invalid token on AndroidAndroid 上的 Google 电子表格 API 无效令牌
【发布时间】:2015-07-04 15:05:32
【问题描述】:

我正在尝试创建一个 Android 应用程序,该应用程序在 google 驱动器上创建一个电子表格,然后将数据保存到其中。驱动器部分工作正常,但由于某种原因,当我尝试使用我为谷歌驱动器获得的身份验证时,可能是电子表格 api(Scope https://spreadsheets.google.com/feeds/" 与电子表格 api 我得到 "com.google.gdata.util.AuthenticationException:令牌无效”

这是我的相关代码

    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);

【问题讨论】:

    标签: android google-drive-api google-sheets


    【解决方案1】:

    我终于发现问题是你需要打电话

    service.setAuthSubToken(credential.getToken());
    

    而不是

    service.setUserToken(credential.getToken());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      • 2021-01-26
      • 2017-10-18
      • 2011-11-27
      • 2012-03-28
      • 1970-01-01
      • 2019-04-18
      相关资源
      最近更新 更多