带有图片的Android twitter推特

时间:2016-07-28 05:14:31

标签: android twitter social-networking twitter-fabric

我第一次在我的Android应用程序中集成twitter,我能够发布推文,我想从应用程序共享图像,我有图像的URL(存储在AmazonS3服务器上)。我想分享这个图像来自我的Android应用..请任何人都可以提供实现此目的的步骤

public class TwitterIntegration extends GlobalActivity {
    TwitterAuthClient mTwitterAuthClient;
    TwitterApiClient twitterApiClient;
    Preferences preferences;
    UserHistory userHistory;
    StatusesService statusesService;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        preferences=HWUtil.getPreferences(this);
        userHistory=preferences.getUserHistory();
        mTwitterAuthClient=new TwitterAuthClient();
        mTwitterAuthClient.authorize(this, new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {
                TwitterSession session = result.data;
                Log.d("user", session.getUserName());
                Log.d("user", session.toString());
                HWUtil.showToast(TwitterIntegration.this, session.getUserName());
                twitterApiClient = TwitterCore.getInstance().getApiClient(session);
                statusesService = twitterApiClient.getStatusesService();
                statusesService.update("Hii from android", null, null, null, null,
                        null, null, null, new Callback<Tweet>() {
                            @Override
                            public void success(Result<Tweet> result) {
                                HWUtil.showToast(TwitterIntegration.this, "Posted SucessFully");
                                if(Validator.isNotNull(userHistory.getHistoryPictures())&& userHistory.getHistoryPictures().length>0){
                                    shareImage();
                                }



                            }

                            public void failure(TwitterException exception) {
                                HWUtil.showToast(TwitterIntegration.this, "Failed to post");
                            }
                        });
            }

            @Override
            public void failure(TwitterException exception) {
                HWUtil.showToast(TwitterIntegration.this, exception.getMessage());
            }
        });


    }

    private void shareImage() {
        if(Validator.isNotNull(twitterApiClient)){
            MediaService mediaService=twitterApiClient.getMediaService();

        }
    }


    @Override
    protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
        // Pass the activity result to the login button.
        super.onActivityResult(requestCode,responseCode,intent);
        mTwitterAuthClient.onActivityResult(requestCode, responseCode, intent);
    }

}

1 个答案:

答案 0 :(得分:1)

首先我们必须下载@amit所说的所有图像我使用asynctask

l1 <- trimws(scan("yourfile.txt", what ="", sep="\n", quiet=TRUE))
lst <- strsplit(l1, " ")
lst2 <- lapply(lst, function(x) as.numeric(x[-(1:2)]))
d1 <- setNames(do.call(rbind.data.frame, lapply(lst, 
                function(x) x[1:2])), c("exp", "sample"))
d1$listdata <- lst2

然后我们必须使用rest api将其上传到twitter以使用状态服务获取媒体ID,然后我们必须将其与所有媒体ID的状态一起发布为post。这完全适合我。