How to call Oauth 1.0 API in Android?
Asked Answered
T

1

7

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.

Toulouse answered 24/4, 2016 at 9:54 Comment(1)
Please check my answer in following link https://mcmap.net/q/153303/-auth-1-0-oauth_signature-creation-android-for-magento-apiEngineer
L
11

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!

Lorolla answered 24/4, 2016 at 12:2 Comment(4)
how can I integrate OAuthProvider.class in provider() method?I want to integrate woocommerce api.Berneicebernelle
Hi Mrugesh. Did u get your answer ?Dugald
can you please explain about OAuthProvider.class ?Chrono
what is the dependency for OAuthProvider.class?Idiophone

© 2022 - 2024 — McMap. All rights reserved.