twitter中的无效令牌访问格式(android app)

时间:2013-01-18 06:42:08

标签: java android linkedin

这是我的Stack跟踪,我已经完成了Twitter集成以共享数据,如果我点击该活动的按钮,应用程序崩溃并强制关闭,有人可以帮助解决这个问题吗?

01-18 11:19:08.114: E/AndroidRuntime(332): FATAL EXCEPTION: main
01-18 11:19:08.114: E/AndroidRuntime(332): java.lang.RuntimeException: Unable to start   activity ComponentInfo{com.example.com/com.example.com.Singlemenuitem}: java.lang.IllegalArgumentException: Invalid access token format.
01-18 11:19:08.114: E/AndroidRuntime(332):  at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-18 11:19:08.114: E/AndroidRuntime(332):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-18 11:19:08.114: E/AndroidRuntime(332):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-18 11:19:08.114: E/AndroidRuntime(332):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-18 11:19:08.114: E/AndroidRuntime(332):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

这是我的主要活动,其中错误是......

public class Singlemenuitem  extends Activity implements OnClickListener{

private TwitterApp mTwitter;
private static final String CONSUMER_KEY = "6JyIkj71ZqG4wk3YF0Y4hw";
private static final String CONSUMER_SECRET =    "9kYPpGzUTgDGa5NawwYAqERQtaVRnY9T8CrePXpA";
private enum FROM {
    TWITTER_POST, TWITTER_LOGIN
};

private enum MESSAGE {
    SUCCESS, DUPLICATE, FAILED, CANCELLED
};
   @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_list_item);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
    .permitAll().build();
   StrictMode.setThreadPolicy(policy);

   mTwitter = new TwitterApp(this, CONSUMER_KEY, CONSUMER_SECRET);
    //share twitter
        final ImageView twitter = (ImageView) findViewById(R.id.twitter);
        twitter.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v){
                TwDialogListener mTwLoginDialogListener = null;
                mTwitter.setListener(mTwLoginDialogListener);
                mTwitter.resetAccessToken();
        if (mTwitter.hasAccessToken() == true) {
            try {
                mTwitter.updateStatus(String.valueOf(Html
                        .fromHtml(TwitterApp.MESSAGE)));

                // File f = new File("/mnt/sdcard/android.jpg");
                // mTwitter.uploadPic(f, String.valueOf(Html
                // .fromHtml(TwitterApp.MESSAGE)));

                postAsToast(FROM.TWITTER_POST, MESSAGE.SUCCESS);
            } catch (Exception e) {
                if (e.getMessage().toString().contains("duplicate")) {
                    postAsToast(FROM.TWITTER_POST, MESSAGE.DUPLICATE);
                }
                e.printStackTrace();
            }
            mTwitter.resetAccessToken();
        } else {
            mTwitter.authorize();
        }
    }

    private void postAsToast(FROM twitterPost, MESSAGE success) {
        switch (twitterPost) {
        case TWITTER_LOGIN:
            switch (success) {
            case SUCCESS:
                Toast.makeText(Singlemenuitem.this, "Login   Successful",               Toast.LENGTH_LONG)
                        .show();
                break;
            case FAILED:
                Toast.makeText(Singlemenuitem.this, "Login Failed",   Toast.LENGTH_LONG).show();
            default:
                break;
            }
            break;
        case TWITTER_POST:
            switch (success) {
            case SUCCESS:
                Toast.makeText(Singlemenuitem.this, "Posted Successfully", Toast.LENGTH_LONG)
                        .show();
                break;
            case FAILED:
                Toast.makeText(Singlemenuitem.this, "Posting Failed", Toast.LENGTH_LONG)
                        .show();
                break;
            case DUPLICATE:
                Toast.makeText(Singlemenuitem.this,
                        "Posting Failed because of duplicate message...",
                        Toast.LENGTH_LONG).show();
            default:
                break;
            }
            break;
        }


    TwDialogListener mTwLoginDialogListener = new TwDialogListener() {

        public void onError(String value) {
            postAsToast(FROM.TWITTER_LOGIN, MESSAGE.FAILED);
            Log.e("TWITTER", value);
            mTwitter.resetAccessToken();
        }

        public void onComplete(String value) {
            try {
                mTwitter.updateStatus(TwitterApp.MESSAGE);
                postAsToast(FROM.TWITTER_POST, MESSAGE.SUCCESS);
            } catch (Exception e) {
                if (e.getMessage().toString().contains("duplicate")) {
                    postAsToast(FROM.TWITTER_POST, MESSAGE.DUPLICATE);
                }
                e.printStackTrace();
            }
            mTwitter.resetAccessToken();
        }
    };

0 个答案:

没有答案