Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

android - usingOAuth2 deprecated?

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

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

The method usingOAuth2(Context, String, String...) from the type GoogleAccountCredential is deprecated

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So, the simple answer to my own question is

replace:

GoogleAccountCredential crd = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE);

with

GoogleAccountCredential crd = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(DriveScopes.DRIVE_FILE));


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...