Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Oauth 1.0 API in Android?

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.

like image 930
Rishi Avatar asked Apr 24 '16 09:04

Rishi


1 Answers

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!

like image 95
Vihas Avatar answered Sep 20 '22 18:09

Vihas