linkedin-api
linkedin-api copied to clipboard
`get_conversation_details` does not work
I get KeyError: 'elements'
when trying to use get_conversation_detals with a profile urn, no matter what profile I use. Has the API changed recently? What is the working way to get a conversation urn for a profile?
you are using the wrong urn. use
api.get_profile('publicIdentifier')
where public identifier can be also found on the link on the search bar. then the dictionary output will show a key as
'entityUrn': 'urn:li:fs_profile:XXXXXXXXXXXXXXXXXXXXXXX',
do not use the whole value of that key, but just the XXXXXXXXXXXXXXXXXXXXXXX
part on
api.get_conversation_detais('XXXXXXXXXXXXXXXXXXXXXXX')
After investigation:
get_conversation_details gives status 500.
I changed the function like this to handle it: `def get_conversation_details(self, profile_urn_id): """Fetch conversation (message thread) details for a given LinkedIn profile.
:param profile_urn_id: LinkedIn URN ID for a profile
:type profile_urn_id: str
:return: Conversation data
:rtype: dict
"""
# passing `params` doesn't work properly, think it's to do with List().
# Might be a bug in `requests`?
res = self._fetch(
f"/messaging/conversations?\
keyVersion=LEGACY_INBOX&q=participants&recipients=List({profile_urn_id})"
)
data = res.json()
if "status" in data:
return data
else:
if data["elements"] == []:
return {}
item = data["elements"][0]
item["id"] = get_id_from_urn(item["entityUrn"])
return item`