android - 使用 OAuthSignpostClient 的 android jtwitter 授权问题

标签 android oauth jtwitter

我目前正在开发我的第一个 Android 应用程序,但我在连接到 Twitter 以发布来 self 的 Android 3.2 模拟器的状态时遇到问题。模拟器似乎能够连接到互联网,因为我可以使用内置浏览器连接到网络,并且我设置了 DNS 服务器。

![应用][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: ERROR/AndroidRuntime(409): winterwell.jtwitter.TwitterException: oauth.signpost.exception.OAuthCommunicationException: 与服务提供商的通信失败:null

最佳答案

您在那里使用的是仅限桌面的示例代码。

最佳做法是创建一个将用户发送到授权 URL 的 Intent 。然后捕获来自 Twitter 的后续 Web 请求,其中包含授权信息。

Marakana 也有一个 Android/JTwitter 的例子: http://marakana.com/forums/android/examples/312.html

关于android - 使用 OAuthSignpostClient 的 android jtwitter 授权问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7443788/

相关文章:

android - 在 android 1.6 中启动一个没有过渡动画的新 Activity

java - 访问 ListView 项目字符串的最简单方法是什么?

c# - 使用 post 请求获取授权 token

Android回调URL调用oncreate

android - Cordova:如何在不使用相机应用程序的情况下拍照

安卓: GridView

android - 使 Android WebView 不存储 cookie 或密码

oauth - 如何为 Yahoo 开发者帐户启用 mail-r 范围

java - Jtwitter 的 100 多个搜索结果