CallBack after Twitter authentication

前端 未结 3 848
天命终不由人
天命终不由人 2021-01-15 00:39

I\'m trying to integrate twitter to my app, but I can\'t seem to get it to work.

This is my code:

public class OAuthForTwitter extends Activity {

           


        
相关标签:
3条回答
  • 2021-01-15 01:29

    I have solved this. Not exactly the way you have developed, but a slight different way. Here are the steps describing what i did.

    1. Use webview instead of opening it in web browser: One of the key advantage doing it is , you can track the url redirects.

    2. call setWebViewClient method of your webview and override shouldOverrideUrlLoading method of your class, i have used inner class.

    3. You will have url parameter in your method. Check whether it starts with your own call back url or not, (Note: This url contains User Token and user secret that is necessary for authorization).

    4. After you finish your task, you can hide the activity or remove the webView or any thing you desire.

    EDIT : This is the oAuth way usually used in web application, so we don't need xAuth way. (In case other community members don't know)

    Hope it will help you.

    0 讨论(0)
  • 2021-01-15 01:31

    Your callback URL should be "sosInternational://HierBenIkNu" (instead of "sosInternational:///HierBenIkNu") in the Java code.

    private final String CALLBACKURL = "sosInternational://HierBenIkNu";
    
    0 讨论(0)
  • 2021-01-15 01:36

    Ok, it was quite a dumb mistake.

    My <intent-filter> wasn't inside an application..

    This is how it is now:

    <activity 
            android:name=".OAuthForTwitter"
            android:label="@string/app_name"
            android:configChanges="orientation|keyboardHidden"
            android:launchMode="singleInstance">
            <intent-filter>  
                <action android:name="android.intent.action.VIEW"></action>  
                <category android:name="android.intent.category.DEFAULT"></category>  
                <category android:name="android.intent.category.BROWSABLE"></category>  
                <data android:scheme="sosInternational" android:host="OAuthForTwitter"></data>  
            </intent-filter>
        </activity>
    

    This kind off works, it just loads the whole app from start.

    Isn't there a way to just 'go back' to the last activity without restarting the whole app?

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