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: 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)
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
}
Code: Select all
params = {
"q": "organization",
"organization": organization_urn,
"timeIntervals.timeGranularityType": "DAY",
"timeIntervals.timeRange.start": start_ms,
"timeIntervals.timeRange.end": end_ms
}
Mobile version