Twitter Login Authentication in Android?

2019-01-19 08:18发布

I have to do Login Authentication to post the tweets. I got the Jtwitter.jar and SignPost.jar file from this link. As far as i searched, the xAuth Authendication is more efficient. But i did not get any simple tutorial or piece of code for Login Authendication yet. I found this Article and used this code. thats get NullPointerException.

I created the customer key and Secret key also used the code where got the jar site. That gets Verification Error.

Please Share some idea or steps to follow to verify the username and password of the user?

Edit:

I want to post to from the user's account. what do you prefer to use the Api whether Jtwitter or Oauth? and Tell me How-to or Related Articles ?

2条回答
我只想做你的唯一
2楼-- · 2019-01-19 08:59

@Jorgesys - you are wrong to say "JTwitter is for basic authentication". JTwitter supports OAuth, and the example code shows OAuth being used. See the JTwitter documentation

xAuth isn't as good for users because you need to collect user passwords. You'll have to ask Twitter support for permission if you want to use xAuth.

So OAuth may be more work, but it is the best thing to use.

On Android, you'll want to direct the user to an authentication page. The following code should work. You can make things smoother if you can handle callbacks.

// Make an oauth client
// "oob" is for the slightly clunky enter-your-pin method
OAuthSignpostClient oauthClient = new OAuthSignpostClient(MY_OAUTH_KEY, MY_OAUTH_SECRET, "oob");

// open the authorisation page in the user's browser
URI url = client.authorizeUrl();
Intent myIntent = new Intent(Intent.VIEW_ACTION);
myIntent.setData(url);
startActivity(myIntent);

// TODO Get the pin from the user 
String pinCode;

oauthClient.setAuthorizationCode(pinCode);
// Store the authorisation token details for future use
Object accessToken = client.getAccessToken();

// Make a Twitter object
Twitter twitter = new Twitter("my-name", oauthClient);
// Set your status
twitter.setStatus("Messing about in Java");
查看更多
姐就是有狂的资本
3楼-- · 2019-01-19 09:05

heres is a excellent example to implement OAuth for Twitter in Android

http://github.com/brione/Brion-Learns-OAuth by Brion Emde

heres the video

JTwitter is for basic autentication, Avoid the OAuthocalypse in August 16th twitter aunthentication is about to change http://www.4psmarketing.com/blog/world-cup-2010-delays-twitter-oauthocalypse

查看更多
登录 后发表回答