5

I am having difficulty getting a share on LinkedIn. I am trying to post a LinkedIn share via LinkedIn API V2 and every time I make the post request I get a request timed out (status 504) answer from the server. Here is my code :

myPost = {
      'author': 'urn:li:person:' + this.uid,
      'lifecycleState': 'PUBLISHED',
      'specificContent': {
          'com.linkedin.ugc.ShareContent': {
              'shareCommentary': {
                  'text': 'Hello World! This is my first Share on LinkedIn!'
              },
              'shareMediaCategory': 'NONE'
          }
      },
      'visibility': {
          'com.linkedin.ugc.MemberNetworkVisibility': 'PUBLIC'
      }
  }

header = {
  'Content-Type': 'application/json',
  'X-Restli-Protocol-Version': '2.0.0',
  'Authorization': 'Bearer ' + token
};

this.http.post('https://api.linkedin.com/v2/ugcPosts', myPost, header).then(res => {
    alert(JSON.stringify(res));
  })
  .catch(err => {
    alert(JSON.stringify(err));
  });

And here is the error message :

{
    "message": "Request timed out",
    "status": 504
}

It's an angular-ionic project and I use the native cordova-plugin-advanced-http to make my post request. I had no issue to sign in with LinkedIn, get my access token and retrieve data from LinkedIn using the same native plugin and the LinkedIn API V2.

On my LinkedIn developer account, to the usage & limits page, I can see the API call to create method.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
  • Hi, welcome to StackOverflow! It often helps to get an answer if you include what you have already tried and how it did not fit your needs. Also details about error messages you get when you attempt to perform your share would be useful to help diagnose the issue. – William Patton Feb 22 '19 at 23:58
  • If you're still encountering timeout issues, please submit a ticket to linkedin.zendesk.com and include the response headers received from your POST request. – Christopher Ou Feb 27 '19 at 00:49

3 Answers3

5

Timeouts related to POST endpoints in LinkedIn API v2 can happen if LinkedIn is unable to parse the request body. The solution to the example posted here is to turn myPost into a proper JSON string, eg. json.dumps(myPost).

The timeout can also happen if missing the 'Content-Type': 'application/json' header which just bit me while playing with their API using ruby.

David Backeus
  • 455
  • 6
  • 8
0

helped for me with same issue on python

head = {
'Authorization': 'Bearer '+token, 'X-Restli-Protocol-Version': '2.0.0'
}

body = {
    "author": 'urn:li:person:'+ID,
    "lifecycleState": "PUBLISHED",
    "specificContent": {
        "com.linkedin.ugc.ShareContent": {
            "shareCommentary": {
                "text": "Hello World! This is my first Share on LinkedIn!"
            },
            "shareMediaCategory": "NONE"
        }
    },
    "visibility": {
        "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
    }
}

requests.post('https://api.linkedin.com/v2/ugcPosts', data=json.dumps(body),headers=head)
  • i get this issue " Error parsing request body to json Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: (com.linkedin.data.ByteString$ByteArrayVectorInputStream); line: 7, column: 249]" when my post has "-". – augustine jenin Jun 07 '19 at 06:55
0

There's really no reason to be using an obfuscated, js-lib plugin to just share a link on LinkedIn. All you need is:

https://www.linkedin.com/sharing/share-offsite/?url={url}

Source: Microsoft LinkedIn Share URL Documentation.

For example, this works for me:

https://www.linkedin.com/sharing/share-offsite/?url=http://www.wikipedia.org/

Works fine:

No authentication problem at all. Then just make your own button and hyperlink it. No problem.

If you are interested in a regularly maintained GitHub project that keeps track of this so you don't have to, check it out! Social Share URLs

Social Share URLs Image

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133