Announcement Announcement Module
Collapse
No announcement yet.
400 Bad Request error in post message to LinkedIn Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 400 Bad Request error in post message to LinkedIn

    Hi,

    I am getting 400 Bad Request response from LinkedIn on posting new share message. I am using SNAPSHOT builds for LinkedIn. This worked flawlessly earlier, but with recent Snapshot builds this seems broken again.

    Request in in JSON format:
    {"comment":"xcxcxccxcx","content":{"title":"xcxcxc cxc","submittedUrl":"google.com"},"visibility":{"c ode":"anyone"}}
    I verified the headers for proper content type and is populated as "application/json".

    API EndPoint:
    http://api.linkedin.com/v1/people/~/shares

    Response from LinkedIn:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <error>
    <status>400</status>
    <timestamp>1368533172919</timestamp>
    <request-id>X5ZB57YRQ5</request-id>
    <error-code>0</error-code>
    <message>Couldn't parse share document: error: Unexpected element: CDATA</message>
    </error>

    I tried to sent the same request with proper content-type in REST console @ http://developer.linkedin.com/rest-console and is working fine.

    Can you kindly help me in fixing this.

    Regards
    Rama Krishna

  • #2
    By any chance are you using access tokens that were obtained prior to this becoming a problem? Recently I changed Spring Social LinkedIn to take advantage of the fact that LinkedIn now supports OAuth 2. But if you're still using old access tokens, it probably won't work. You'll need to authorize again, get a new token, and try again.

    If that's not the problem, then could you give me a bit more info. Specifically, which API binding method were you calling when you got this?

    Comment


    • #3
      Hi,

      I regenerated the tokens and I retested with fresh data. I tried by adding the code to sample project(spring-social-showcase) too. I still got the same exception.

      I added the following code to LinkedInConnectionsController.java:

      Code:
              String image="http://xxx.xxxxx.com/imgs/wizard_step4.png", url="google.com", title="sample", desc="descrrr";	
      	NewShare share = new NewShare();
      	share.setComment(desc);
      	NewShareContent nsc = new NewShareContent();
      	nsc.setSubmittedImageUrl(image);
      	nsc.setSubmittedUrl(url);
      	nsc.setTitle(title);
      	share.setContent(nsc);
      	NewShareVisibility nsv = new NewShareVisibility();
      	nsv.setCode(NewShareVisibilityCode.ANYONE);
      	share.setVisibility(nsv);
      	boolean isAuth = linkedIn.isAuthorized(); // This is returning true, so authorization is good. 
              URI uri = linkedIn.networkUpdateOperations().share(share);
      	String postId = String.valueOf(uri.toString()).substring(uri.toASCIIString().indexOf("key=")+4);


      I also added the following permissions to scope variable, just in case, to make sure its not creating the problem:
      Code:
      	<input type="hidden" name="scope" value="r_basicprofile r_fullprofile r_emailaddress r_network r_contactinfo rw_nus rw_groups w_messages" />

      The error message received from LinkedIn
      Code:
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <error>
        <status>400</status>
        <timestamp>1368603413572</timestamp>
        <request-id>VK1O09Y377</request-id>
        <error-code>0</error-code>
        <message>Couldn't parse share document: error: Unexpected element: CDATA</message>
      </error>

      I also tried by recreating the application in LinkedIn. Still, the issue persists.

      Kindly let me know if you need any more information.

      Best Regards
      Rama Krishna


      Originally posted by habuma View Post
      By any chance are you using access tokens that were obtained prior to this becoming a problem? Recently I changed Spring Social LinkedIn to take advantage of the fact that LinkedIn now supports OAuth 2. But if you're still using old access tokens, it probably won't work. You'll need to authorize again, get a new token, and try again.

      If that's not the problem, then could you give me a bit more info. Specifically, which API binding method were you calling when you got this?

      Comment


      • #4
        Thanks...the additional information you gave helped me track this down and I've been able to recreate it on my end.

        My theory is that (for some unknown reason) LinkedIn is expecting the content as XML. But we're sending it as JSON. The JSON sent is the unexpected CDATA. But I'm still puzzled as to why it is expecting XML and what changed recently to make that happen.

        I've created https://jira.springsource.org/browse/SOCIALLI-28 to track this. Watch that issue to know when I've got a fix in place (it may not be today, but I'll try to get to it soon.)

        Comment


        • #5
          I posted the same JSON, produced by the REST template, in REST-Console of LinkedIn. It worked fine. So, JSON also works for LinkedIn.

          It could be incompatible content-type with content. Content-type is set as XML but JSON is sent.

          Thank you for taking it up.

          Comment


          • #6
            I have found and have fixed the problem with XML vs. JSON. But after the fix, now I'm getting 401s, even with what I *know* to be a good access token. I'm going to go ahead and push the XML/JSON fix now although there's a good chance you'll start getting 401s now. I'm still looking into the 401 issue.

            FWIW, I obtained a valid access token outside of Spring Social and used it in a simple browser-based request using the oauth2_access_token query parameter (per the instructions at http://developer.linkedin.com/documents/authentication) and was still getting a 401. This seems like a LinkedIn problem, but I'm still investigating. Let me know if the latest snapshot build works for you or if you start getting 401s.

            Comment


            • #7
              Follow-up. I have it working now. It seems that LinkedIn's API wants you to send access tokens via the oauth2_access_token parameter (I knew that much already), but will not accept the request if you also send the token as an OAuth2 Bearer token in the Authorization header. Go figure.

              So, I removed the Authorization header and now it seems to work. I even tried a small-scale "share" operation much like what you were doing and it worked. Let me know if you see otherwise.

              Comment

              Working...
              X