Android Question Using Oauth1 REST API

Aneets

New Member
Hi All,
Firstly I am very new to B4A ( only installed 3 Days ago) and wish I had discovered it years ago.
I am trying to connect to a REST API that uses Oaut1 and am having trouble doing this. I have done this multiple times in VB.net but am struggling to find a way to do this in B4A. below is the code that i use in VB.net.

B4X:
        Dim oauth1 As New Chilkat.OAuth1
        oauth1.ConsumerKey = "....."
        oauth1.ConsumerSecret = "..."
        oauth1.Token = "....."
        oauth1.TokenSecret = "....."
        oauth1.Realm = "1234567"
        '  The signature method can be HMAC-SHA1 or HMAC-SHA256
        oauth1.SignatureMethod = "HMAC-SHA1"

        oauth1.OauthUrl = ":  https://rest.na2.netsuite.com/app/site/hosting/restlet.nl"

        oauth1.OauthMethod = "GET"

        '  Generate an initial nonce so that Chilkat knows the desired size of the nonce.
        Dim success As Boolean = oauth1.GenNonce(11)
        'oauth1.AddParam("script", "665")
        'oauth1.AddParam("deploy", "1")
        'oauth1.AddParam("type", "getpickslipnotdispatch")
        'oauth1.AddParam("recordtype", "salesorder")


        Dim rest As New Chilkat.Rest

        rest.AddQueryParam("script", "665")
        rest.AddQueryParam("deploy", "1")
        rest.AddQueryParam("type", "getpickslipnotdispatch")
        rest.AddQueryParam("recordtype", "salesorder")

        '  Tell the REST object to use the OAuth1 object for authentication.
        '  Also, indicate that the OAuth authentication parameters should be query parameters
        '  and not located within the Authorization header.
        Dim bUseQueryParams As Boolean = False
        success = rest.SetAuthOAuth1(oauth1, bUseQueryParams)

        '  Make the initial connection (without sending a request yet) to the WooCommerce endpoint at your Wordpress blog.
        Dim bTls As Boolean = True
        Dim port As Integer = 443
        Dim bAutoReconnect As Boolean = True
        success = rest.Connect("rest.na2.netsuite.com", port, bTls, bAutoReconnect)
        If (success <> True) Then
            Console.WriteLine(rest.LastErrorText)
            Exit Sub
        End If


        '  Send a GET request to list orders.

        '  When the request is sent, the OAuth1 object's Timestamp and Nonce properties are automatically
        '  regenerated.  Also, the OAuth1 object's OauthMethod property is automatically set to the HTTP method
        '  used for the request (in this case it is "GET").
        Dim responseJson As String = rest.FullRequestNoBody("GET", "/app/site/hosting/restlet.nl")
        If (rest.LastMethodSuccess <> True) Then
            'Console.WriteLine(rest.LastErrorText)
            Exit Sub
        End If

This is just a GET Request but I will need to do PUT and DELETE as well.

I hope someone can point me in the right direction.
Thanks in advance for any assistance and help provided it is all very appreciated.
 

DonManfred

Expert
Licensed User
Longtime User
Did you checked if the Google OAuth2 class works?


Which Api exactly are you trying to communicate with? Can you post a link to the REST documentation?
 
Last edited:
Upvote 0

Aneets

New Member
Thanks DonManfred for your response to my question.
I have left work for the day so will have to check your suggestion in the morning.
In relation to your question to the details of the API. I am trying to connect to a Netsuite RestLet. This is a custom REST endpoint that my NetSuite guru writes for me. They use Oauth1 and as the code above shows have to have some parameters passed to them to work correctly.
What information would assist with helping me resolve this issue.

Regards,
Aneets
 
Upvote 0

Aneets

New Member
HI Erel and DonManfred,
I have been working away at this for a full day now and have got my head around most of it. what I am having the most trouble is working out how to correctly encode the base string. It is supposed to be encoded using percent-encoding as mentioned in this document. https://tools.ietf.org/html/rfc5849#section-3.6

Can you help me work out how to achieve this?

Thanks in advance,
Aneets
 
Upvote 0
Top