问题描述
我一直在开发一个使用 Google Drive API 的 Android 应用.它最初是从 此处的快速入门示例构建的.API 调用的简化序列(此处未显示正确的错误处理)是:
I've been working on an Android App that uses Google Drive API. It was originally build from the quickstart example here. The simplified sequence of API calls (with proper error handling not shown here) is:
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 更新后,我收到了警告
It has been working fine and I am just about to release my App. But suddenly, after Drive API update, I'm getting a warning
方法 usingOAuth2(Context, String, String...) 从类型GoogleAccountCredential 已弃用
发生了什么事?有没有其他方法可以获取凭证?快速入门示例的编辑版本是否可以在任何地方使用?
What's happening? Is there another way to obtain credentials? Is there an edited version of quickstart example available anywhere?
提前感谢您的澄清.肖恩
Thanks in advance for any clarification. sean
推荐答案
所以,我自己的问题的简单答案是
So, the simple answer to my own question is
替换:
GoogleAccountCredential crd =GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE);
与
GoogleAccountCredential crd =GoogleAccountCredential.usingOAuth2(这个,Arrays.asList(DriveScopes.DRIVE_FILE));
这篇关于usingOAuth2 已弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!