1

可能重复:
Twitter API 不接受 Android 应用的回调 URL

当我尝试将 twitter 集成到我的 android 应用程序中时,它会显示此错误...

为什么会显示此错误?

这个错误有什么解决办法??

任何人都可以帮助我吗?

07-16 17:44:05.875: W/System.err(395): oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: http://twitter.com/oauth/request_token
07-16 17:44:05.905: W/System.err(395):  at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
07-16 17:44:05.905: W/System.err(395):  at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
07-16 17:44:05.905: W/System.err(395):  at net.londatiga.android.TwitterApp$2.run(TwitterApp.java:117)
07-16 17:44:05.905: W/System.err(395): Caused by: java.io.FileNotFoundException: http://twitter.com/oauth/request_token
07-16 17:44:05.905: W/System.err(395):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1061)
07-16 17:44:05.915: W/System.err(395):  at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
07-16 17:44:05.925: W/System.err(395):  at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
07-16 17:44:05.925: W/System.err(395):  at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
5:44 PM

代码....

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

    private static final String twitter_consumer_key = "xxxxxxxxxxxx";
    private static final String twitter_secret_key = "xxxxxxxxxxxxx";

    @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();
        }
    };
} 
4

1 回答 1

0

检查这些条件 1. 在 twitter 中注册应用程序以获取 twitter_consumer_key 和 twitter_secret_key。2.检查app是否有上网权限

于 2012-07-16T13:23:26.627 回答