2013-03-03 2 views
5

Google 드라이브에서 파일을 가져 오기 위해 Android 앱을 작성할 계획입니다.GoogleAccountCredential에서 새로 고침 토큰을 제공합니까?

저장 용량이 큰 경우 파일을 다운로드하는 데 몇 시간이 걸릴 것입니다. 이 경우 프로세스를 완료하려면 새로 고침 토큰이 필요합니다. 지금까지 내가 아는 한 GoogleAccountCredential은 새로 고침 토큰을 얻는 방법을 제공하지 않습니다.

토큰을 보내고 새로 고침 토큰을 websevice에 보내서 내 앱 대신 파일을 다운로드하고 서버에 저장하려고합니다.

GoogleAccountCredential에서 새로 고치는 토큰을 가져 오는 방법이 있습니까?

+0

해결책을 찾았습니까? – tttony

답변

0
난 당신이 오프라인 액세스 유형 GoogleAuthorizationaflow를 요청해야합니다, 당신은 새로 고침 토큰을 얻으려면 안드로이드에 대한하지만, 자바 잘 모릅니다

..


흐름처럼 = 새로운 GoogleAuthorizationCodeFlow.Builder (httpTransport, jsonFactory, clientSecrets, SCOPES) .setAccessType ("오프라인"). setApprovalPrompt ("force"). build();

+0

답장 user2032988 주셔서 감사합니다. 하지만 GoogleAccountCredential을 사용하여 GoogleAuthorizationCodeFlow에 대한 래퍼로 작동하는 토큰을 가져오고 두 단계로 토큰을 가져올 것입니다. 먼저 반환 된 Authcode를 구문 분석하고 toke에 액세스하기를 원합니다. – Manoj

0

예. 새로 고침 토큰을 얻으려면 서버 쪽 범위를 요청해야합니다.

String MY_SCOPE = ""; // put your score here, e.g. "https://www.googleapis.com/auth/gmail.readonly" 
String CLIENT_ID = "1234567890-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com"; 
String SERVER_SCOPE = "oauth2:server:client_id:" + CLIENT_ID + ":api_scope:" + MY_SCOPE; 

GoogleAccountCredential cred = new GoogleAccountCredential(context, SERVER_SCOPE).setSelectedAccountName("[email protected]"); 
cred.getToken(); 
관련 문제