如何使用OAuth从我的Andr​​oid应用程序登录Twitter的? [英] How to Login twitter using Oauth from my android application?

查看:126
本文介绍了如何使用OAuth从我的Andr​​oid应用程序登录Twitter的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出这是一个Twitter客户端应用程序。这意味着它连接到Twitter使用OAuth。注册我的应用程序,以Twitter和得到了所有我的钥匙,但现在我没有一个想法如何与Twitter连接我的应用程序。我做了下面的一些code不在话下。请帮我了..

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 not have an idea how to connect my application with twitter. I have done some code mention below. Please help me out..

Twitter twitter=new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Consumer key, Consumer secret);
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken=null;
Log.i("Acces Token",accessToken.getToken());     
Log.i("Acces Tokensec",accessToken.getTokenSecret());

在此先感谢。

Thanks in advance.

推荐答案

您有两种选择。排名第一的是更容易。编号2是比较困难的。

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

头号只是继续你离开的地方。 当您得到一 requestToken ,你将需要启动一个的WebView 指向的网址requestToken.getAuthorizationURL()。然后,用户将登录并选择是否允许访问他/她的账户。接下来,如果他/她打允许,访问code将显示用户必须复制/粘贴到自己的应用程序。您将使用与的键getOAuthAccessToken()(我想,我用后述的艰难的方式)来获取,你应该在某处永久存储的身份验证令牌。此时,您进行身份验证。

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.

排名第二的也仍然在那里你减去一个细节不放过...... twitter.getOAuthRequestToken(REDIRECT_URL)。 这REDIRECT_URL必须你的Twitter开发者帐户内先被置位。然后按照同样的步骤,头号不同之处在于你的WebView需要进行定制。你需要使用 setWebViewClient()的WebView ,并创建一个扩展的新类 WebViewClient 。在 WebViewClient 的onPageStarted,检查网址是否与您返回URL启动。然后拿到OAuth的信息:

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");

使用了 oauth_verifier twitter.getOAuthAccessToken()来让你的令牌。

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

这篇关于如何使用OAuth从我的Andr​​oid应用程序登录Twitter的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆