from requests_oauthlib import OAuth1Session
import json
# Note 정보를 입력하세요
payload = {"test_mode": True,
"post_id": "1939667242318541239"
,
"info": {
"text": "test note text. http://source.com",
"classification": "misinformed_or_potentially_misleading",
"misleading_tags": ["missing_important_context"],
"trustworthy_sources": True,
}}
# 요청 생성
oauth = OAuth1Session(
client_key='REPLACE_ME',
client_secret='REPLACE_ME',
resource_owner_key='REPLACE_ME',
resource_owner_secret='REPLACE_ME',
)
# 요청 실행
response = oauth.post(
"https://api.twitter.com/2/notes",
json=payload,
)
if response.status_code != 201:
raise Exception(
"요청이 오류를 반환했습니다: {} {}".format(response.status_code, response.text)
)
print("응답 코드: {}".format(response.status_code))
# 응답을 JSON으로 저장
json_response = response.json()
print(json.dumps(json_response, indent=4, sort_keys=True))