I am trying to get company shares in Python with the requests library. My app has the additional Marketing Developer Platform access and I am a super admin for the company page I am trying to get shares from. The authorsation described here works fine. I can successfully place a https://api.linkedin.com/v2/me GET request.
Based on this tutorial, the LinkedIn documentation and this suggestion I wrote the following code using the LinkedIn test organisation ID:
def get_posts(access_token):
URL = "https://api.linkedin.com/v2/shares"
headers = {'q':'owners', 'owners': 'urn:li:organization:2414183',
'Authorization':'Bearer {}'.format(access_token),'X-Restli-Protocol-Version':'2.0.0'}
response = requests.get(url=URL, headers=headers)
print(response.json())
get_posts(access_token)
The error code is {'serviceErrorCode': 0, 'message': 'Resource shares does not exist', 'status': 404}
The error message remains the same when using the actual company ID (9481327).
The answer to this question does not provide any code or hint for above problem. This question is based on the V1 api, which is now depreceated.
Up-date 30/05/2022 - below function finds the resource, but cannot process the parameters.
def get_comments(acccess_token):
URL = 'https://api.linkedin.com/v2/shares'
PARAM = {'q':'owners', 'owners':'urn:li:organization:2414183', 'sortBy':'LAST_MODIFIED',
'sharesPerOwner':"100"}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':'Bearer {}'.format(access_token),'X-Restli-Protocol-Version':'2.0.0'}
response = requests.get(url=URL, params = PARAM, headers=headers)
print(response.json())
get_comments(access_token)
{'message': 'Invalid value type for parameter owners', 'status': 400}
The error message is the same for LinkedIn's test page (2414183) and the actual company page I want to access (9481327)
Up-date 01/06/2022 using the ugcPost API provides a similar error message
def get_comments(acccess_token):
URL = 'https://api.linkedin.com/v2/ugcPosts'
PARAM = {'q':'authors', 'authors':'List(urn%3Ali%3Aorganziation%3A9481327)',
'sortBy':'LAST_MODIFIED'
}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':'Bearer {}'.format(access_token),'X-Restli-Protocol-Version':'2.0.0'}
response = requests.get(url=URL, params = PARAM, headers=headers)
print(response.json())
get_comments(access_token)
{'serviceErrorCode': 100, 'message': 'Field Value validation failed in PARAMETER: Data Processing Exception while processing fields [/authors]', 'status': 403}
--> how to specify the owner field correctly?