如何使用Android中的twitter4j库将图片发布到Twitter

Mer*_*şek 0 java twitter android twitter4j

我想在我的应用上将图片发布到twitter.我使用"twitter4j"库只发布文本.但我找不到如何用文字发布图像.感谢帮助.

kod*_*hpa 5

  1. 要发布图像,您必须使用Twitter4j的媒体扩展,并使用TwitPic或YFrog注册您的应用.
  2. 从这些服务中获取KEY和TOKEN然后

    /*
     * 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;
    
    Run Code Online (Sandbox Code Playgroud)