我一直在开发一个使用 Google Drive API 的 Android 应用程序。它最初是从 quickstart example here 构建的. API 调用的简化顺序(此处未显示适当的错误处理)是:
GoogleAccountCredential cred = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE);
cred.setSelectedAccountName("...");
Drive drvSvc = new Drive.Builder (AndroidHttp.newCompatibleTransport(), new GsonFactory(), cred).build();
FileList gooLst = drvSvc.files().list().setMaxResults(MAX_DOWN).setQ(_rqst).execute();
它一直运行良好,我即将发布我的应用程序。但突然间,在 Drive API 更新后,我收到警告
The method usingOAuth2(Context, String, String...) from the type GoogleAccountCredential is deprecated
这是怎么回事?还有另一种获取凭证的方法吗?有没有quickstart example的编辑版本?随处可用?
提前感谢您的澄清。肖恩
最佳答案
所以,我自己的问题的简单答案是
替换:
GoogleAccountCredential crd = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE);
与
GoogleAccountCredential crd = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(DriveScopes.DRIVE_FILE));
关于android - usingOAuth2 已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17429798/