Android中的Twitter登录身份验证?

时间:2010-07-16 19:00:33

标签: android twitter

我必须进行登录身份验证才能发布推文。我从this link获得了Jtwitter.jarSignPost.jar文件。就我搜索而言,xAuth认证更有效率。但我还没有得到任何简单的教程或一段代码用于登录验证。我找到this Article并使用了此代码。那得到NullPointerException

我创建了客户密钥,而密钥也使用了获取jar网站的代码。得到Verification Error

请分享一些想法或步骤,以验证用户的用户名和密码?

编辑:

我想从user's account发帖。您更喜欢使用Api Jtwitter还是Oauth?并告诉我How-toRelated Articles

2 个答案:

答案 0 :(得分:4)

heres是在Android中实现 OAuth for Android

的一个很好的例子 Brion Emde的

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

继承人video

JTwitter 用于基本的身份验证,避免在8月16日推出的 OAuthocalypse 推特身份验证即将发生变化 http://www.4psmarketing.com/blog/world-cup-2010-delays-twitter-oauthocalypse

答案 1 :(得分:1)

@Jorgesys - 说“JTwitter用于基本身份验证”是错误的。 JTwitter支持OAuth,示例代码显示正在使用的OAuth。请参阅JTwitter documentation

xAuth对用户不太好,因为您需要收集用户密码。如果你想使用xAuth,你必须要求Twitter支持许可。

因此,OAuth可能会更有效,但这是最好的选择。

在Android上,您需要将用户定向到身份验证页面。以下代码应该有效。如果你能处理回调,你可以让事情变得更顺畅。

// 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");
相关问题