我正在调用 linkedin 图像 API 来初始化上传。我正在使用 insomnia 来拨打电话,我拥有未过期的访问令牌(4 天前创建)以及以下所有权限/范围 (
r_1st_connections_size,r_ads,r_ads_reporting,r_basicprofile,r_organization_admin,r_organization_social,rw_ads,rw_organization_admin,w_member_social,w_organization_social
)。以下是在 python 中导出的调用代码。我拥有所有正确的权限,并且 linkedin 帐户是活动经理,但每次我不断收到下面包含的 403 禁止错误。
输入/调用:
import requests
url = "https://api.linkedin.com/rest/images"
querystring = {"action":"initializeUpload"}
payload = {"initializeUploadRequest": {
"owner": "urn:li:organization:219257106",
"mediaLibraryMetadata": {
"associatedAccount": "urn:li:sponsoredAccount:513356194",
"assetName": "My media library asset"
}
}}
headers = {
"cookie": "lidc=%22b%3DTB09%3As%3DT%3Ar%3DT%3Aa%3DT%3Ap%3DT%3Ag%3D4706%3Au%3D9%3Ax%3D1%3Ai%3D1721511524%3At%3D1721531628%3Av%3D2%3Asig%3DAQEhRosuJdmI8XOks_ogULcqJ4z6ElBm%22; lang=v%3D2%26lang%3Den-us; bcookie=%22v%3D2%26e770df25-8e43-4671-8db7-93d77b371de4%22; lidc=%22b%3DOB24%3As%3DO%3Ar%3DO%3Aa%3DO%3Ap%3DO%3Ag%3D4952%3Au%3D1%3Ax%3D1%3Ai%3D1721511020%3At%3D1721597420%3Av%3D2%3Asig%3DAQEU3F9_YkGbWbcYIHaAzem7-iWdhPs3%22",
"Content-Type": "application/json",
"User-Agent": "insomnia/9.3.2",
"LinkedIn-Version": "202401",
"X-RestLi-Protocol-Version": "2.0.0",
"Authorization": "Bearer *Access key is here*"
}
response = requests.request("POST", url, json=payload, headers=headers, params=querystring)
print(response.text)
输出/响应:
{"message":"Accessing this image resource is forbidden. Please check your permissions for this resource","status":403}
Content-Type: application/json
x-restli-error-response: true
x-restli-protocol-version: 2.0.0
Date: Sat, 20 Jul 2024 21:37:14 GMT
X-Li-Fabric: prod-ltx1
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://www.linkedin.com/li/rep"}],"include_subdomains":true}
NEL: {"report_to":"network-errors","max_age":1296000,"success_fraction":0.00066,"failure_fraction":1,"include_subdomains":true}
Transfer-Encoding: chunked
Connection: keep-alive
X-Li-Source-Fabric: prod-lor1
X-Li-Pop: prod-lor1-x
X-LI-Proto: http/1.1
X-LI-UUID: AAYdtJ2D23vSK/bl+U5hKQ==
Set-Cookie: lidc="b=TB09:s=T:r=T:a=T:p=T:g=4706:u=9:x=1:i=1721511434:t=1721531628:v=2:sig=AQHyDuL8gOEgjhxrLJrv0Tmw4FnAgczf"
X-LI-Route-Key: "b=TB09:s=T:r=T:a=T:p=T:g=4706:u=9:x=1:i=1721511434:t=1721531628:v=2:sig=AQHyDuL8gOEgjhxrLJrv0Tmw4FnAgczf"
我尝试制作一个新的访问令牌,使用
MediaLibraryMetadata
,我尝试使用视频 api 并遇到同样的问题。我期待一个带有 uploadUrl 的 200 OK 状态代码来上传图像,以及类似以下响应示例的内容。
{
"value": {
"uploadUrlExpiresAt": 1650567510704,
"uploadUrl": "https://www.linkedin.com/dms-uploads/C4E10AQFoyyAjHPMQuQ/uploaded-image/0?ca=vector_ads&cn=uploads&sync=0&v=beta&ut=08zHQjMjAOLqc1",
"image": "urn:li:image:C4E10AQFoyyAjHPMQuQ"
}
}
收到 403 禁止错误的原因是尝试将图片上传到赞助帐户的媒体库。目前,Linkedin API 不支持此功能。
虽然可以使用 Images API 和 Videos API 将图片和视频上传到 个人 Linkedin 帐户,但 无法 直接将媒体上传到赞助帐户。
可以在此处找到 Linkedin 的官方文档中提到的此限制: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/ads/asset-management/media-library?tabs=http#known-issues
可能的解决方法:
-
使用 Linkedin Campaign Manager UI: 要将图片上传到的赞助帐户,请继续使用 Linkedin Campaign Manager 界面。这是上传媒体到赞助帐户的推荐方法。
-
创建单独的 API 请求以获取资产: 上传图片后,可以使用 Images API 或 Videos API 使用其相应的 URN 检索其详细信息。
请记住,Linkedin 的 API 及其功能可能会发生变化。始终建议查阅其官方文档以获取最新信息和更新。
标签:python,linkedin-api From: 78773997