LinkedIn OrganizationPageStatistics API gibt 400 PARAM_INVALID für timeIntervals zurück (REST.li 2.0)Python

Python-Programme
Anonymous
 LinkedIn OrganizationPageStatistics API gibt 400 PARAM_INVALID für timeIntervals zurück (REST.li 2.0)

Post by Anonymous »

Ich rufe den LinkedIn-OrganisationPageStatistics-Endpunkt mit der REST.li 2.0-API auf, erhalte jedoch weiterhin einen 400 PARAM_INVALID-Fehler im Zusammenhang mit dem timeIntervals-Parameter.
Laut der offiziellen Dokumentation (li-lms-2025-11) ist timeIntervals ein Objekt, keine Liste.
Fehlerantwort

Code: Select all

{
"errorDetailType": "com.linkedin.common.error.BadRequest",
"message": "Invalid param. Please see errorDetails for more information.",
"errorDetails": {
"inputErrors": [
{
"description": "Invalid value for param; wrong type or other syntax error",
"input": {
"inputPath": {
"fieldPath": "timeIntervals"
}
},
"code": "PARAM_INVALID"
}
]
},
"status": 400
}
Code

Code: Select all

def fetch_linkedin_analytics_and_save(user, account):
organization_urn = f"urn:li:organization:{account.page_id}"
access_token = account.access_token
start_ms = int(
(datetime.now() - timedelta(days=90)).timestamp() * 1000)
end_ms = int(datetime.now().timestamp() * 1000)

base_url = "https://api.linkedin.com/rest/organizationPageStatistics"

LINKEDIN_API_VERSION = os.environ.get("LINKEDIN_API_VERSION", "202511")

headers = {
"Authorization": f"Bearer {access_token}",
"Linkedin-Version": LINKEDIN_API_VERSION,
"X-Restli-Protocol-Version": "2.0.0",
"Content-Type": "application/json"
}

time_intervals_str = f'(timeGranularityType:DAY,timeRange:(start:{start_ms},end:{end_ms}))',
params = {
"q": "organization",
"organization": organization_urn,
'timeIntervals.timeGranularityType': 'DAY',
'timeIntervals.timeRange.start': start_ms,
'timeIntervals.timeRange.end': end_ms
}
print(params)

response = requests.get(base_url, headers=headers, params=params)

if response.status_code != 200:
print(response.text)
Versuch 1 – REST.li-Objektzeichenfolge

Code: Select all

time_intervals_str = (
f"(timeGranularityType:DAY,"
f"timeRange:(start:{start_ms},end:{end_ms}))"
)

params = {
"q": "organization",
"organization": organization_urn,
"timeIntervals": time_intervals_str
}
Versuch 2 – Abgeflachte Parameter

Code: Select all

params = {
"q": "organization",
"organization": organization_urn,
"timeIntervals.timeGranularityType": "DAY",
"timeIntervals.timeRange.start": start_ms,
"timeIntervals.timeRange.end": end_ms
}
Ihre Hilfe wird geschätzt

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post