Android Question Connecting to Site Using oAuth2.0

Discussion in 'Android Questions' started by johnB, May 3, 2015.

  1. johnB

    johnB Active Member Licensed User

    Hi, I'm trying to connect to a site that has OAuth2.0 working. I have received the following documentation

    - https://docs.google.com/document/d/12WFbF93Sw0b_3iBippvLvx4swbJQ47eu7fT0VLyvGUw/edit#

    I don't understand what

    1. the "scope" string represents and

    2. what is the significance of the Redirect URI. They have given me a web address that is registered in my name but I don't do anything with it except for using it to host a test Web Site

    They have given me a ClientID and ClientSecret, an Authorization Token and an Access Token but I can't get it to give me the access code

    The app brings up their web site login page, then gives me the error message

    "java.lang.Exception: Sub service_start signature does not match expected signature"

    Thanks in anticipation

    PS I have the GMail Contacts app working
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the signature of Service_Start sub?
     
  3. johnB

    johnB Active Member Licensed User

    Apologies for my lack of systems programming knowledge, I've always done business stuff.

    This is the complete Log, as you can see it falls over on Line 31 (End Sub of Service_Create)
    but the Log says Sub service_start signature ..................

    --------------------------------------------------
    ** Activity (main) Create, isFirst = true **


    ** Activity (main) Resume **


    Starting Job: GetAccessToken


    ** Service (httputilsservice) Create **


    ** Service (httputilsservice) Start **


    An error occurred:


    (Line: 31) End Sub
    java.lang.Exception: Sub service_start signature does not match expected signature.
    public static anywheresoftware.b4a.pc.RemoteObject anywheresoftware.b4a.samples.gmailcontacts.httputilsservice_subs_0._service_start() throws java.lang.Exception

    ----------------------------------------------------------

    Is the subs.txt file of any asistance in the "\Objects\shell\bin\classes" folder

    I'm sorry, I don't think that this is what you were after but I don't know how to get it

    Regards
     
  4. DonManfred

    DonManfred Expert Licensed User

    Post you service_create sub
     
  5. johnB

    johnB Active Member Licensed User

    Code:
    Sub Service_Create
        
    If init = False Then Process_Globals
        
    If TempFolder = "" Then TempFolder = File.DirInternalCache
        
    If hcIsInitialized = False Then
            hc.Initialize(
    "hc")
            hcIsInitialized = 
    True
        
    End If

    End Sub
    This is the message I get when I run it in Release mode

    LogCat connected to: 0123456789ABCDEF
    --------- beginning of /dev/log/system


    --------- beginning of /dev/log/main


    ** Activity (main) Create, isFirst = true **


    ** Activity (main) Resume **


    38


    Starting Job: GetAccessToken


    ** Service (httputilsservice) Create **


    ** Service (httputilsservice) Start **


    Error. Url=https://api.sharesight.com/oauth2/token Message=Unauthorized


    {"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}


    ** Service (httputilsservice) Destroy **
     
  6. DonManfred

    DonManfred Expert Licensed User

    Sorry, my fault...
    So not service_create, post the service_start sub please
     
  7. johnB

    johnB Active Member Licensed User

    Code:
    Sub Service_Start
        
    If HttpUtils.Tasks.IsInitialized = False Then Return
        taskToRequest.Initialize
        finishTasks = 
    0
        task = 
    0
        countWorking = 
    0
        
    Do While task < HttpUtils.Tasks.Size
            ProcessNextTask
            
    If countWorking >= maxTasks Then Exit
        
    Loop
    End Sub
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    The signature should be:
    Code:
    Sub Service_Start (StartingIntent As Intent)
     
  9. johnB

    johnB Active Member Licensed User

    Thanks Erel, That got thru to the end of the job done for Access Token but

    1. I need to tied up my program and ensure the id's etc are all in the right place because I tried many variations and

    2. I presume that they need to get back to me about what the "scope" should be. I've emailed them

    regards
     
  10. johnB

    johnB Active Member Licensed User

    The return strings I'm getting back from the site are in JSON format rather than xml format. I've tried numerous combinations of the parse function

    Code:
    Parser.Initialize(HttpUtils.GetString(url))
                Map1 = Parser.NextValue        .NextArray        .NextObject
                
    Dim m As Map 'helper map for navigating
                m = Map1.Get("portfolios")
    NextValue, NextArray and NextObject but couldn't get a returned file.

    I've put the request sent by the app eg

    https://portfolio.sharesight.com/ap...d251a94...................???????????????????

    into a browser

    And get the following returned

    {"portfolios":[{"id":553??,"name":"Bowe??????????","default_sale_allocation_method":"fifo","cg_discount":"Self Managed Super Fund","rwtr_rate":33.0,"trader":true,"broker_email_api_enabled":true,"broker_email_key":"johnb?????","financial_year_end_month_id":6,"interest_method":"simple","api_email_notification":"ON","contract_note_email_notification":"ON"}]}

    Which is what I expect from their documentation

    I get the error message "Task not completed successfully." from the line : Map1 = Parser.NextValue or .NextArray or .NextObject

    I've searched the forum but couldn't find any reference to returning JSON formatted files in oAuth2.0
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    johnB likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice