我打算編寫一個Android應用程序以從Google雲端硬盤中獲取文件。GoogleAccountCredential是否提供刷新令牌?
如果存儲空間很大,肯定需要幾個小時來下載文件。在這種情況下,我需要刷新令牌來完成該過程。據我所知,GoogleAccountCredential
不提供任何方法來獲取刷新令牌。
我想將令牌和刷新令牌發送到web服務,以便它代表我的應用下載文件並將其存儲在服務器中。
有什麼辦法從GoogleAccountCredential
獲取刷新標記嗎?
我打算編寫一個Android應用程序以從Google雲端硬盤中獲取文件。GoogleAccountCredential是否提供刷新令牌?
如果存儲空間很大,肯定需要幾個小時來下載文件。在這種情況下,我需要刷新令牌來完成該過程。據我所知,GoogleAccountCredential
不提供任何方法來獲取刷新令牌。
我想將令牌和刷新令牌發送到web服務,以便它代表我的應用下載文件並將其存儲在服務器中。
有什麼辦法從GoogleAccountCredential
獲取刷新標記嗎?
我不知道安卓但在Java中,如果你想獲得刷新令牌,你必須請求GoogleAuthorizationaflow脫機訪問類型..
像
流量=新GoogleAuthorizationCodeFlow.Builder(httpTransport,jsonFactory,clientSecrets,範圍) .setAccessType(「offline」)。setApprovalPrompt(「force」)。build();
感謝您的回覆user2032988。 但我想使用GoogleAccountCredential來取回令牌,因爲它作爲GoogleAuthorizationCodeFlow的包裝函數,我將分兩步獲取令牌,我真的不想分析首先返回的Authcode,然後交換它以訪問toke。 – Manoj 2013-03-04 00:56:23
是的,它的確如此。 你需要問一個服務器端的示波器來獲取刷新令牌:
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();
你是否找到了解決方案? – tttony 2013-04-01 05:38:07