LinkedIn API: Fehler 400 „Organisationsberechtigungen müssen verwendet werden, wenn die Organisation als Autor verwendetPython

Python-Programme
Guest
 LinkedIn API: Fehler 400 „Organisationsberechtigungen müssen verwendet werden, wenn die Organisation als Autor verwendet

Post by Guest »

Ich verwende die LinkedIn-API, um eine Umfrage auf meiner LinkedIn-Seite zu veröffentlichen, erhalte jedoch weiterhin die folgende Fehlermeldung:

Die Umfrage konnte nicht gepostet werden. Antwort: 400 {"message="Organisationsberechtigungen müssen verwendet werden, wenn die Organisation als Autor verwendet wird",status":400

Ich glaube, das Problem liegt vor hängt mit fehlenden Berechtigungen zusammen. Ich verstehe, dass ich möglicherweise die Berechtigung rw_organization benötige, weiß aber nicht, wie ich sie aktivieren kann. Beim Einrichten meiner App habe ich alle verfügbaren Berechtigungen gewährt, aber ich sehe keine Option zum spezifischen Hinzufügen oder Aktivieren von rw_organization.
code:

Code: Select all

import mysql.connector
import requests
import random

def shorten_option(option, max_length=25):
...

def extract_hashtag(question_group):
...
def fetch_poll_data():
...

def post_linkedin_poll(question, options, extracted_hashtag):
access_token = "..."
organization_id = "..."
api_url = "https://api.linkedin.com/rest/posts"
additional_hashtags = "#Practice"
post_text = f"{question}\n\n{extracted_hashtag} {additional_hashtags}"
poll_data = {
"question": question,
"options": [{"text": option} for option in options],
"settings": {"duration": "THREE_DAYS"}
}
payload = {
"author": f"urn:li:organization:{organization_id}",
"commentary": post_text,
"visibility": {"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"},
"distribution": {
"feedDistribution": "MAIN_FEED",
"targetEntities": [],
"thirdPartyDistributionChannels": []
},
"lifecycleState": "PUBLISHED",
"content": {
"poll": poll_data
},
"isReshareDisabledByAuthor": False
}

# Set the headers
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
"LinkedIn-Version": "202408"
}

try:
response = requests.post(api_url, json=payload, headers=headers)
if response.status_code == 201:
print("Poll posted successfully on LinkedIn!")
elif response.status_code == 500:
print(f"LinkedIn Server Error: {response.text}.")
else:
print(f"Failed to post poll. Response: {response.status_code} {response.text}")

except Exception as e:
print(f"An error occurred while posting the poll: {e}")

def main():
# Fetch poll data from the database
question, options, extracted_hashtag = fetch_poll_data()

if question and options and extracted_hashtag:
# Post the poll to LinkedIn
post_linkedin_poll(question, options, extracted_hashtag)
else:
print("Failed to fetch poll data. No poll posted.")
if __name__ == "__main__":
main()
Weiß jemand, wie man dieses Problem löst oder die App so konfiguriert, dass sie die erforderlichen Berechtigungen zum Posten verwendet?
Jede Hilfe wäre sehr dankbar!< /P>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post