from requests_oauthlib import OAuth1Session
import json
# ノート情報を入力してください
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))