How to call Oauth 1.0 API in Android?

独自空忆成欢 提交于 2019-11-30 17:49:05

问题


I am trying to call Context.io API from Android which is based on Oauth 1.0 Authentication.

Can you please suggest me how I can create request for Oauth1.0 standard or Please, anyone can provide me the sample code of Oauth1.0 request example on that standard.

Thank you very much.


回答1:


You can use scriblejava library to access Oauth 1.0 2-legged APIs.

In Android Studio App griddle add following dependency:

compile 'org.scribe:scribe:1.3.5'

And simply use following code:

    String consumerKey    = "XXXX"; //api key
    String consumerSecret = "XXXX"; //api secret
    String requestUrl = "your context.io request url";

    OAuthService service = new ServiceBuilder()
            .provider(OAuthProvider.class)
            .apiKey(consumerKey)
            .apiSecret(consumerSecret)
            .build();

    OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl);

    Token accessToken = new Token("", ""); //not required for context.io
    service.signRequest(accessToken, request);

    Response response = request.send();
    Log.d("OAuthTask",response.getBody());

Hope it helped!



来源:https://stackoverflow.com/questions/36821628/how-to-call-oauth-1-0-api-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!