gpt4 book ai didi

python - 获取 LinkedIn 公司股票 Python

转载 作者:行者123 更新时间:2023-12-05 04:29:14 26 4
gpt4 key购买 nike

我正在尝试使用 requests library 获取 Python 中的公司股份.我的应用程序具有额外的营销开发人员平台访问权限,并且我是公司页面的 super 管理员,我正试图从中获取共享。作者described here工作正常。我可以成功放置 https://api.linkedin.com/v2/me获取请求。

基于this tutorial , LinkedIn documentationthis suggestion我使用 LinkedIn 测试组织 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)

错误代码是{'serviceErrorCode': 0, 'message': 'Resource shares does not exist', 'status': 404}

使用实际公司 ID (9481327) 时,错误消息保持不变。 The answer to this question没有为上述问题提供任何代码或提示。 This question基于 V1 api,现已弃用。

更新 30/05/2022 - 下面的函数找到资源,但无法处理参数。

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': '参数所有者的值类型无效', 'status': 400}
LinkedIn 的测试页面 (2414183) 和我要访问的实际公司页面 (9481327) 的错误消息相同

更新 01/06/2022 使用 ugcPost API提供类似的错误信息

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': 'PARAMETER 中的字段值验证失败:处理字段时出现数据处理异常 [/authors]', 'status': 403} -->如何正确指定所有者字段?

最佳答案

我遇到了类似的问题并找到了两个解决方案 - 通过 ugcPosts-API 或 shares-API。

ugcPosts-API:

def get_posts(access_token, organisation):
headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization':'Bearer {}'.format(access_token),'X-Restli-Protocol-Version':'2.0.0'}

url = 'https://api.linkedin.com/v2/ugcPosts?q=authors&authors=List(urn%3Ali%3Aorganization%3A' + str(organisation) + str(")")
response = requests.get(url=url, headers=headers)
return response.json()

共享 API:

def get_shares(access_token, organisation):
headers = {'Content-Type': 'application/x-www-form-urlencoded','Authorization':'Bearer {}'.format(access_token)}

URN = 'urn:li:organization:' + str(organisation) + str('&sortBy=LAST_MODIFIED&sharesPerOwner=100')
url = 'https://api.linkedin.com/v2/shares?q=owners&owners=' + URN
response = requests.get(url=url, headers=headers)
return response.json()

... 而“access_token”是访问 token ,“organisation”是 ID。 (例如“2414183”)

需要注意的是后一种解决方案,标题中不应包含“X-ReSTLi-Protocol-Version”信息。

关于python - 获取 LinkedIn 公司股票 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72406550/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com