Не удалось опубликовать опрос. Ответ: 400 {"message":"При использовании организации в качестве автора необходимо использовать разрешения организации","status":400}
Я считаю, что проблема связано с отсутствием разрешений. Я понимаю, что мне может понадобиться разрешение rw_organization, но я не знаю, как его включить. При настройке приложения я предоставил все доступные разрешения, но не вижу возможности конкретно добавить или включить rw_organization.
код:
Код: Выделить всё
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()
Будем очень признательны за любую помощь!< /п>
Подробнее здесь: https://stackoverflow.com/questions/793 ... ing-organi
Мобильная версия