0

我尝试通过此链接与 twitter 建立联系

https://github.com/lorensiuswlt/AndroidTwitter

    public class TestConnect extends Activity {
private TwitterApp mTwitter;
private CheckBox mTwitterBtn;

private static final String twitter_consumer_key = "xxx";
private static final String twitter_secret_key = "xxx";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    mTwitterBtn = (CheckBox) findViewById(R.id.twitterCheck);

    mTwitterBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onTwitterClick();
        }
    });

    mTwitter    = new TwitterApp(this, twitter_consumer_key,twitter_secret_key);

    mTwitter.setListener(mTwLoginDialogListener);

    if (mTwitter.hasAccessToken()) {
        mTwitterBtn.setChecked(true);

        String username = mTwitter.getUsername();
        username        = (username.equals("")) ? "Unknown" : username;

        mTwitterBtn.setText("  Twitter (" + username + ")");
        mTwitterBtn.setTextColor(Color.WHITE);
    }

    Button goBtn = (Button) findViewById(R.id.button1);

    goBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(TestConnect.this, TestPost.class));
        }
    });
}

private void onTwitterClick() {
    if (mTwitter.hasAccessToken()) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setMessage("Delete current Twitter connection?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       mTwitter.resetAccessToken();

                       mTwitterBtn.setChecked(false);
                       mTwitterBtn.setText("  Twitter (Not connected)");
                       mTwitterBtn.setTextColor(Color.GRAY);
                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();

                        mTwitterBtn.setChecked(true);
                   }
               });
        final AlertDialog alert = builder.create();

        alert.show();
    } else {
        mTwitterBtn.setChecked(false);

        mTwitter.authorize();
    }
}

private final TwDialogListener mTwLoginDialogListener = new TwDialogListener() {
    @Override
    public void onComplete(String value) {
        String username = mTwitter.getUsername();
        username        = (username.equals("")) ? "No Name" : username;

        mTwitterBtn.setText("  Twitter  (" + username + ")");
        mTwitterBtn.setChecked(true);
        mTwitterBtn.setTextColor(Color.WHITE);

        Toast.makeText(TestConnect.this, "Connected to Twitter as " + username, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onError(String value) {
        mTwitterBtn.setChecked(false);

        Toast.makeText(TestConnect.this, "Twitter connection failed", Toast.LENGTH_LONG).show();
    }
};
   }

我已经在我的设备上成功运行了这个应用程序......但是当我尝试连接时,我收到消息 Twitter 连接失败并且我无法发布消息

请帮助...我是 twitter 与 android 连接的新手...在此先感谢

4

1 回答 1

0

你可以参考这个 - TwitterOAuthView

于 2013-09-13T19:32:08.943 回答