使用 OAuthSignpostClient 进行 android jtwitter 授权的问题
我目前正在开发我的第一个 Android 应用程序,但在连接到 Twitter 以从 Android 3.2 模拟器发布状态时遇到问题。模拟器似乎能够连接到互联网,因为我可以使用内置浏览器连接到网络,并且我设置了 DNS 服务器。
![application][1]
当我单击更新按钮时,整个应用程序失败并给出以下错误:
抱歉!应用程序 Burnett Street Hustle v1(进程 com.burnettstreethustle)已意外停止,请重试。 由于代码
编译并运行直到我单击“更新”按钮,因此我不确定出了什么问题,因为错误消息也不清楚。
这是我的代码:
public class TwitterTab extends Activity implements OnClickListener {
static final String TAG = "TwitterTab";
Button buttonUpdate;
EditText textStatus;
public void onClick(View src) {
String JTWITTER_OAUTH_KEY = "***************************";
String JTWITTER_OAUTH_SECRET = "*****************************"; // i do have these codes as the app is registered, they have just been blanked out and are not the cause of the problem.
OAuthSignpostClient oauthClient = new OAuthSignpostClient(JTWITTER_OAUTH_KEY,JTWITTER_OAUTH_SECRET, "http://127.0.0.1:1066/Twitter/Callback.aspx");
oauthClient.authorizeUrl();
String v = OAuthSignpostClient.askUser("Please enter the verification PIN from Twitter");
oauthClient.setAuthorizationCode(v);
Object accessToken = oauthClient.getAccessToken();
Twitter jtwit = new Twitter("burnettstrhustl", oauthClient);
String status = textStatus.getText().toString();
Log.d(TAG, "Clicked on "+ status);
// Toast
Toast.makeText(this, textStatus.getText(), Toast.LENGTH_LONG).show();
// set twitter status
jtwit.setStatus(status);
//reset status string
textStatus.setText("");
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.twitter);
buttonUpdate = (Button) findViewById(R.id.buttonUpdate);
textStatus = (EditText) findViewById(R.id.textStatus);
// Add listener
buttonUpdate.setOnClickListener(this);
}
我也不确定如何正确使用回调 url,必须输入哪个 url 才能进行授权?
谢谢。
更新堆栈跟踪:
09-16 17:05:41.537:错误/AndroidRuntime(409):winterwell.jtwitter.TwitterException:oauth.signpost.exception.OAuthCommunicationException:与服务提供商的通信失败:null
i am currently working on my first android app ever and i have a problem connecting to twitter to post a status from my Android 3.2 emulator. The emulator seems to be able to connect to the internet as I can use the built in browser to connect to the net and i set up the DNS server.
![application][1]
when I click the update button the entire application fails and gives the following error:
Sorry! The application Burnett Street Hustle v1 (process com.burnettstreethustle) has stopped unexpectedly, please try again.
Since the code compiles and runs up until i click the "Update" button im not sure what is wrong since the error message is also unclear.
here is my code:
public class TwitterTab extends Activity implements OnClickListener {
static final String TAG = "TwitterTab";
Button buttonUpdate;
EditText textStatus;
public void onClick(View src) {
String JTWITTER_OAUTH_KEY = "***************************";
String JTWITTER_OAUTH_SECRET = "*****************************"; // i do have these codes as the app is registered, they have just been blanked out and are not the cause of the problem.
OAuthSignpostClient oauthClient = new OAuthSignpostClient(JTWITTER_OAUTH_KEY,JTWITTER_OAUTH_SECRET, "http://127.0.0.1:1066/Twitter/Callback.aspx");
oauthClient.authorizeUrl();
String v = OAuthSignpostClient.askUser("Please enter the verification PIN from Twitter");
oauthClient.setAuthorizationCode(v);
Object accessToken = oauthClient.getAccessToken();
Twitter jtwit = new Twitter("burnettstrhustl", oauthClient);
String status = textStatus.getText().toString();
Log.d(TAG, "Clicked on "+ status);
// Toast
Toast.makeText(this, textStatus.getText(), Toast.LENGTH_LONG).show();
// set twitter status
jtwit.setStatus(status);
//reset status string
textStatus.setText("");
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.twitter);
buttonUpdate = (Button) findViewById(R.id.buttonUpdate);
textStatus = (EditText) findViewById(R.id.textStatus);
// Add listener
buttonUpdate.setOnClickListener(this);
}
Im also not sure how to use the callback url properly, which url must go in there for the authorization to occur?
Thanks.
UPDATE Stack Trace:
09-16 17:05:41.537: ERROR/AndroidRuntime(409): winterwell.jtwitter.TwitterException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在那里使用仅限桌面的示例代码。
最佳实践是创建将用户发送到授权 URL 的意图。然后捕获来自 Twitter 的后续带有授权信息的 Web 请求。
Marakana 还有一个 Android / JTwitter 示例:
http://marakana.com/forums/android/examples/312.html
You're using Desktop-only example code there.
Best practice is to create an intent to send the user off to the authorisation URL. And then catch the subsequent web request from Twitter that carries the authorisation info.
Marakana also have an Android / JTwitter example:
http://marakana.com/forums/android/examples/312.html
您的应用程序是否在清单文件中设置了互联网权限?
Does your app have the internet permission set in the manifest file?