Posting image with spring social

java
springsocial

#1

I’m trying to post a tweet with image which is uploaded in my system. I get response “media type unrecognized”.

public Tweet postTweet(TwitterPost twitterPost) {
        TweetData tweetData = new TweetData(
            twitterPost.getPostText() + "\n" +
            twitterPost.getHashtags());
            if (nonNull(twitterPost.getImagePath())){
                Resource image = new FileSystemResource(twitterPost.getImagePath());
                tweetData = tweetData.withMedia(image);
                LOG.info("Trying to tweet with image url {}");
            }
        LOG.info("Sending tweet {}");
        return twitter.timelineOperations().updateStatus(tweetData);
    }

When i post with UrlResource and put image url from intertnet it works fine. How i can post a tweet with my own file. Is it even possible or the file has to be reachable from my server with url. What am I doing wrong.


#2

I think you’d have to ask the Spring Social folks about this. The Twitter API supports image uploading, but I don’t know how Spring is implementing this.