views:

212

answers:

3

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.

A: 

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 [email protected].

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.

peSHIr
+2  A: 

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.

Moncader
A: 

http://lowequalityapps.com/how-to-post-a-tweet-to-twitter-with-the-oauth-api/

the above link contains code on receiving tokens and submitting a tweet using OAUTH

Jay_EL