Announcement Announcement Module
No announcement yet.
Attaching image to twitter status Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Attaching image to twitter status

    Hello everyone!

    It's me again . I am trying to attach an image to twitter status update. I am using the following code:

    Twitter twitter = new TwitterTemplate(consumerKey, consumerSecret, twitterAccessToken, accessTokenSecret);
    StatusDetails statusDetails = new StatusDetails();
    statusDetails.setLocation(-34.61178f, -58.41731f);
    Resource photo = getUploadResource("C:/foto.jpg", "PHOTO DATA");
    twitter.timelineOperations().updateStatus("Este es un nuevo mensaje para la pagina twitter desde spring social 231234", photo, statusDetails);
    But when I try this I get:

    WARN: org.springframework.web.client.RestTemplate  - POST request for "" resulted in 403 (Forbidden); invoking error handler
    Exception in thread "main" Error creating status.
    	at org.springframework.web.client.RestTemplate.handleResponseError(
    	at org.springframework.web.client.RestTemplate.doExecute(
    	at org.springframework.web.client.RestTemplate.execute(
    	at org.springframework.web.client.RestTemplate.postForObject(
    	at com.solopaquetes.service.Test.main(

    I have these settings:

    OAuth settings
    Access level Read, write, and direct messages

    Your access token
    Access level Read and write

    Any ideas whats going on? Thanks
    Last edited by tunilopez; Oct 18th, 2011, 10:25 PM.

  • #2
    I see nothing wrong with what you're doing here. In fact, I copied-n-pasted it into a test class (changing only where I fetched the resource image from) and it worked fine for me.

    The one thing I don't know about is what the resource in question looks like, because I don't know what's behind the getUploadResource() method. One thing you might try (at least temporarily) is to use Spring's FileSystemResource, which is what I did in my test (and the only thing that differs with what you're doing. It may be a case where the resource your sending isn't acceptable to Twitter for some reason. You might try uploading a different image, too and see if that helps.


    • #3
      You are right. It works.

      It seems that I was creating the Resource incorrectly. I created a FileSystemResource as you said and it worked perfectly.

      Thank you


      • #4
        I really like your informative and useful tips.
        It really looks great to me.