0

I just developed on twitter integration app for android 2.3 using twitter4j, but now I want to use this app for android 4.0 and I have to change my app because it dosen't work,

I want to import mu currentUset variables like: screen_name, user_id, and profile_image_url too! And then i just want to import my followers and followings.

Can someone help me please? I was desesperated! I was goggling but I don't have any answer about this.

4

2 回答 2

0

您可以使用Twitter Helper将 Twitter 集成到您的 Android 应用程序中。它非常简单。

于 2015-02-20T12:23:23.047 回答
0

将此代码添加到您的 main_activity

private TwitterApp mTwitter;
private static final String CONSUMER_KEY = "your consumer key"; 
private static final String CONSUMER_SECRET = "your consumer secret key"; 

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.main);
    mTwitter = new TwitterApp(this, CONSUMER_KEY, CONSUMER_SECRET);
}

public void onClick(View v) {
    mTwitter.setListener(mTwLoginDialogListener);
    mTwitter.resetAccessToken();
    if (mTwitter.hasAccessToken() == true) {
        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();
    } else {
        mTwitter.authorize();
    }
}

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

private TwDialogListener mTwLoginDialogListener = new TwDialogListener() {

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

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

你可以从这里开始 希望它对你有用

于 2013-03-08T10:39:46.253 回答