Android:使用 Twitter4J 登录 Twitter [英] Android: Login with Twitter using Twitter4J

查看:54
本文介绍了Android:使用 Twitter4J 登录 Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过的:

我已经在 twitter 上注册了一个应用程序并获得了 Consumer Key 和 Secret.即使我有各种代码来登录 twitter.这些是我尝试过的:

I already have registered an app in twitter and got Consumer Key and Secret.Even I got various codes to login with twitter.These are what I have tried from:

http://thetechnib.blogspot.com/2011/01/android-sign-in-with-twitter.html

[此链接已失效,您可以查看存档 此处]
http://www.android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application

[This link is dead, you may view an archive here]
http://www.android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application

我遇到的问题:

直到现在,上面的代码带我到 twitter 登录,让我登录并有一个 PIN 来完成登录过程.但我不知道如何使用它来让我的应用程序工作.我检查了整个代码,但发现与 pin 无关.

Till now,above code takes me to twitter login and let me sign in and have a PIN to complete the login process.But I have no idea how to use it to get my app working.I checked the whole code but found nothing related to pin.

其次,当我在 twitter 上注册我的应用程序时,它要求提供回调 URL,但因为它写的是它真的不需要,我跳过指定.(甚至我不知道它应该是什么!)

Secondly,when I registered my app on twitter,it asked for Callback URL but as it was written that its really not needed,i skipped specifying.(Even I don't know what it should be!)

因此,我在我的应用程序中将 null 作为 CallbackURL 提供.

And hence,I am giving null as CallbackURL in my app.

谁能建议我,我如何使用此 PIN 码来完成登录过程并使用户返回到我的应用程序的主要活动?是回调 url 导致问题还是我做错了什么?

Can anyone suggest me,how can I use this PIN to complete login process and get user back to my app's main activity? Is it the callback url which is causing problem or something else I am doing wrong at?

请回复.任何帮助appriciated!谢谢.

Please reply.Any help appriciated! Thanks.

按照 Frankenstein 的建议,我在 github.com/ddewaele/AndroidTwitterSample/downloads 尝试了代码

As suggested by Frankenstein,I tried code at github.com/ddewaele/AndroidTwitterSample/downloads

我添加了我的消费者密钥和消费者秘密以及回调网址:

I added my consumer key and consumer secret along with callback url:

public static final String OAUTH_CALLBACK_SCHEME= "x-oauthflow-twitter";
public static final String OAUTH_CALLBACK_HOST= "callback";
public static final String OAUTH_CALLBACK_URL= OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;

但它给了我这个错误:

Logcat:

11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081): Error during OAUth retrieve request token
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081): oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:239)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at com.ecs.android.sample.twitter.OAuthRequestTokenTask.doInBackground(OAuthRequestTokenTask.java:55)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at com.ecs.android.sample.twitter.OAuthRequestTokenTask.doInBackground(OAuthRequestTokenTask.java:1)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at android.os.AsyncTask$2.call(AsyncTask.java:185)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081):   at java.lang.Thread.run(Thread.java:1096)

当我点击 TWEET 按钮时也会显示黑屏,而不是带我登录 Twitter 屏幕.

Also shows me black screen when i click on TWEET button,instead of taking me to sign in screen of twitter.

天啊,我快疯了……这两天一直在努力!:(请帮忙.

Omg,I am going to be crazy...have been trying since two days! :( please help.

推荐答案

这是因为您的应用已注册为桌面客户端.要覆盖回调 URL,您的应用需要注册为浏览器客户端.

It's because your app is registered as a desktop client. To overwrite callback URL, your app need to be registered as a browser client.

尝试配置一个虚拟回调 URL(http://example.com/或任何你想要的)https://dev.twitter.com/apps/[appid]/settings > 回调 URL并且您的应用将被识别为浏览器客户端.

Try configuring a dummy callback URL (http://example.com/ or whatever you want) at https://dev.twitter.com/apps/[appid]/settings > Callback URL and your app will be recognized as a browser client.

然后尝试@Frankenstein 或@jamn224 代码.

Then try @Frankenstein or @jamn224 code.

这篇关于Android:使用 Twitter4J 登录 Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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