Announcement Announcement Module
Collapse
No announcement yet.
Attaching image to twitter status Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
    Twitter twitter = new TwitterTemplate(consumerKey, consumerSecret, twitterAccessToken, accessTokenSecret);
    StatusDetails statusDetails = new StatusDetails();
    statusDetails.setLocation(-34.61178f, -58.41731f);
    statusDetails.setDisplayCoordinates(true);
    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:

    Code:
    WARN: org.springframework.web.client.RestTemplate  - POST request for "https://upload.twitter.com/1/statuses/update_with_media.json" resulted in 403 (Forbidden); invoking error handler
    Exception in thread "main" org.springframework.social.OperationNotPermittedException: Error creating status.
    	at org.springframework.social.twitter.api.impl.TwitterErrorHandler.handleClientErrors(TwitterErrorHandler.java:105)
    	at org.springframework.social.twitter.api.impl.TwitterErrorHandler.handleError(TwitterErrorHandler.java:58)
    	at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:486)
    	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:443)
    	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    	at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:279)
    	at org.springframework.social.twitter.api.impl.TimelineTemplate.updateStatus(TimelineTemplate.java:245)
    	at com.solopaquetes.service.Test.main(Test.java:30)

    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.

    Comment


    • #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

      Comment


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

        Comment

        Working...
        X