這取決於。你在談論OAuth 1還是OAuth 2?對於前者,您可以使用signpost。對於後者,您可以使用RoboSpice + Google Http Client + Google OAuth Client Library。
如果您使用Google Http Client作爲您的網絡庫,您需要做的是根據GoogleHttpClientSpiceService
創建您自己的HttpClientSpiceService
,您可以在RoboSpice中找到它。然後,你需要的東西是這樣的:
public static HttpRequestFactory createRequestFactory() {
HttpTransport httpTransport = AndroidHttp.newCompatibleTransport();
return httpTransport.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) {
// TODO: authorize or sign request...
// Note that this will authorize/sign ALL the requests you make,
// so you will probably want to improve on that.
}
});
}
剩下的就是真的取決於你,但基本是實現的方式提供第三方登錄,獲得所需要的令牌,併成立了OAuth的庫你的選擇。
來源
2015-05-30 10:32:23
Pin
檢查此鏈接https://guides.codepath.com/android/Consuming-APIs-with-Retrofit –