如果需要多個的OAuth 2.0範圍,use a space-separated list。
oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.userinfo
你問樣品代碼,所以看看Google Docs Upload Sample應用程序,並在此應用程序中查看在this sample Android screen中完成的身份驗證流程(忽略它是關於Google文檔,它仍然首先授權)。您可以獲取整個應用程序並在仿真器中運行它Google API可以在您的手機上展示或運行。授權流程與buttonAuthorize點擊,授權(開始),你在這個方法特別感興趣:
private void gotAccount(Account account)
{
Bundle options = new Bundle();
accountManager.getAuthToken(
account, // Account retrieved using getAccountsByType()
"oauth2:https://www.googleapis.com/auth/userinfo.email oauth2:https://www.googleapis.com/auth/userinfo.userinfo", // Auth scope
//"writely", // Auth scope, doesn't work :(
options, // Authenticator-specific options
this, // Your activity
new OnTokenAcquired(), // Callback called when a token is successfully acquired
null); // Callback called if an error occurs
}
用戶得到該訪問請求畫面:
注意,這是使用'本地'OAuth2機制,不會打開網絡瀏覽器,而是使用首次激活Android手機時提供的身份驗證。
另外請注意,用戶看到的範圍,而不是一個友好的名稱的完整的URL,我haven't找到了解決這個問題的方法,如果你確實發現這將是偉大的,如果你能分享答案。
我已經嘗試過,沒有成功:(,你有沒有使用此之前?如果是這樣,你能提供一個小的代碼片段展示瞭如何?謝謝! – tnacho 2012-07-14 17:44:44
我已經更新了我的答案,包括對樣本的引用,試用了它。 – Mendhak 2012-07-14 18:19:17
我再次嘗試,但沒有成功...幾乎複製了整個源代碼,但必須有其他東西...雖然這感覺像是正確的方向,謝謝! – tnacho 2012-07-14 20:48:50