Android Dev - Callback URL not working… (0_o)

后端 未结 1 1457
无人共我
无人共我 2020-12-15 01:44

I\'m working on an android application for my research, and I am working with OAuth (signpost library) to gain access to user data from a web service which is also a part of

相关标签:
1条回答
  • 2020-12-15 01:58

    In order for the callback uri to work properly you need to add an intent filter similar to the following to your manifest in the activity you want to use it in.

       <intent-filter>          
        <action android:name="android.intent.action.VIEW"/>     
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="appSchema" android:host="appName"/> 
       </intent-filter>
    

    Now, if your activity is using singleInstance/singleTask, you should use something similar to the following:

    @Override
    public void onNewIntent(Intent intent) {
    
        super.onNewIntent(intent);
        Uri uri = intent.getData();
        String oauthToken = uri.getQueryParameter("oauth_token");
        String oauthVerifier = uri.getQueryParameter("oauth_verifier");
    
        //...do what you need with the parameters
    }
    

    if not using singleTask or singleInstance, you can do

    @Override
    public void onResume() {
    
        super.onResume();
        Intent intent = getIntent();
        Uri uri = intent.getData();
        String oauthToken = uri.getQueryParameter("oauth_token");
        String oauthVerifier = uri.getQueryParameter("oauth_verifier");
    
        //...do what you need with the parameters
    }
    

    I believe this should work.

    Also, if I'm not mistaken, the callback url you provide should include the ?, so "appSchema://appName?"

    0 讨论(0)
提交回复
热议问题