Announcement Announcement Module
Collapse
No announcement yet.
Spring Social Facebook post photo failed with 400 error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Social Facebook post photo failed with 400 error

    I used latest spring social showcase, with spring framework 3.2.1 + spring security 3.1.3 + Spring social 1.1.0. Showcase works fine as I can post the status with just text, and also works with post links.
    I need to post a photo, and used following code in FacebookFeedController,

    FileSystemResource photo = new FileSystemResource("c:/temp/g1.png")
    {
    public String getFilename() throws IllegalStateException {
    return "g1.png";
    };
    };
    facebook.mediaOperations().postPhoto( photo,"test");

    SEVERE: Servlet.service() for servlet [default] in context with path [/] threw exception [Request processing failed; nested exception is org.springframework.social.UncategorizedApiExcepti on: (#1) An unknown error occurred] with root cause
    org.springframework.web.client.HttpClientErrorExce ption: 400 Bad Request

    Cannot figure out why it failed.

    Can someone help me?

    Thanks

  • #2
    Nobody replied? Can someone verify it with small changes to the sample?
    Also, how to turn on the debug to show all the http request/response sent/returned from facebook? So I have more clues what may be wrong. I have logs turned on with "debug", but it doesn't print the http request/response with facebook.

    Thanks

    Comment


    • #3
      I set up this pseudo-test (pseudo in that it doesn't assert any specific results):

      Code:
      @Test
      public void postImage() {
      	FacebookTemplate facebook = new FacebookTemplate(MAX_ACCESS_TOKEN); // MAX is a test user
      	FileSystemResource photo = new FileSystemResource("/Users/habuma/PECastle.jpg") {
      		public String getFilename() throws IllegalStateException {
      			return "PECastle.jpg";
      		};
      	};
      	String photoId = facebook.mediaOperations().postPhoto(photo, "Test photo fer ya");
      	System.out.println(photoId);
      }
      And this worked perfectly, as evidenced by the attached screenshot.

      I wondered if it had something to do with yours being a PNG instead of a JPG. But it still worked when I posted a PNG. I can't say for certain why it failed for you. Which version of Spring Social are you using?

      As for turning up logging, there's not a lot of logging done in Spring Social, and certainly nothing that would've helped you with this situation. I'm open to adding more logging, but only where it makes sense...I don't want to litter the code with logging messages just to say I've done logging. One place that *might* be useful to add logging is in FacebookErrorHandler, to log the specific error coming back from Facebook. I'll look into adding that.

      Comment


      • #4
        FWIW, i just tried again, posting a non-image to FB and it gave me the same error you got. By any chance is g1.png not really an image file? Is there something special about it that might make FB think it's a non-image?

        I added the logging that I mentioned in the previous message just to see what you'd get from Facebook. Here's what I got:

        Code:
        DEBUG: {"error":{"message":"(#1) An unknown error occurred","type":"OAuthException","code":1}}
        Not terribly useful. And even somewhat misleading in that the "type" is almost always "OAuthException", even if the problem has nothing to do with OAuth.

        I still think it's good to include that logging message. Perhaps it will prove useful in other cases, even if not for this particular case. I'll commit the code and it will be in the next snapshot build of Spring Social Facebook 1.1.0.BUILD-SNAPSHOT.
        Last edited by habuma; May 8th, 2013, 10:21 AM.

        Comment


        • #5
          You are right!
          I mistakenly used a file which is .pgn(chess game), thought it was .png file.

          Thank you for pointing it out.

          Comment

          Working...
          X