How to post picture to Twitter using twitter4j library in Android

懵懂的女人 提交于 2019-12-23 04:26:37

问题


I want to post image to twitter on my app. I use "twitter4j" library to post only text. But i cannot find how to post image with text. Thanks for help.


回答1:


  1. To post a image you have to use media extension of Twitter4j and register your app with either TwitPic or YFrog .
  2. Get KEY and TOKEN from those services and then

    /*
     * Upload File to twitPic and get url . Then append this url to your twitter message.
     */
    public static String upload_twic_pic(File file)
                    throws TwitterException {
            String url = null;
            if (file != null) {
        Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(TWITPIC_KEY).build();
        ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.PLIXI); //Use ImageUploadFactory
                    url = upload.upload(file);
            }
            return url;
    



回答2:


Here is a link to a one file solution that explains exactly how to integrate picture/text tweets into an android app.




回答3:


You can use socialauth android library

Find SocialAuth Android Here



来源:https://stackoverflow.com/questions/9693586/how-to-post-picture-to-twitter-using-twitter4j-library-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!