How to Login twitter using Oauth from my android application?

后端 未结 2 963
死守一世寂寞
死守一世寂寞 2020-12-17 06:01

I am making an application which is a Twitter client. This means it connects to Twitter with OAuth. I register my application to Twitter and got all my keys, but now I do no

相关标签:
2条回答
  • 2020-12-17 06:28

    If the full OAuth web redirection is not convenient, you could try to use Twitter's xAuth service method to just convert a set of Twitter credentials to an OAuth access token (do that once, and save the token). Much easier on mobile applications, but you need to ask Twitter for permission to use xAuth by emailing api@twitter.com.

    You could also check out another question on StackOverflow for more information on this.

    If your problem is how to actually implement OAuth interactions, you might want to check out OAuth library information on Twitter and/or documentation on the library you are already using.

    0 讨论(0)
  • 2020-12-17 06:33

    You have two choices. Number one is easier. Number two is more difficult.

    Number one just continues where you left off. After you get a requestToken, you will need to launch a WebView and point the URL at requestToken.getAuthorizationURL(). The user will then log in and choose whether or not to allow access to his/her account. Next, if he/she hit allow, an access code will be displayed the user must copy/paste in your your own application. You will use that key with getOAuthAccessToken() (I think, I used the difficult way described later) to get the auth token that you should store somewhere permanently. At this point you are authenticated.

    Number two also continues where you left off minus one detail... twitter.getOAuthRequestToken(REDIRECT_URL). That redirect_url must be set inside your twitter developer account first. Then follow the same steps as number one except that your webview needs to be customized. You need to use setWebViewClient() on your WebView and create a new class that extends WebViewClient. Inside the WebViewClient's onPageStarted, check if the URL starts with your return url. And then get the oauth info:

    String oauth_token = uri.getQueryParameter("oauth_token");
    String oauth_verifier = uri.getQueryParameter("oauth_verifier");
    

    Use the oauth_verifier with twitter.getOAuthAccessToken() to get your token.

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