from requests_oauthlib import OAuth1Session
import json
# 替换为您的 Note 信息
payload = {"test_mode": True,
"post_id": "1939667242318541239"
,
"info": {
"text": "测试 note 文本。http://source.com",
"classification": "misinformed_or_potentially_misleading",
"misleading_tags": ["missing_important_context"],
"trustworthy_sources": True,
}}
# 发起请求
oauth = OAuth1Session(
client_key='请替换为实际值',
client_secret='请替换为实际值',
resource_owner_key='请替换为实际值',
resource_owner_secret='请替换为实际值',
)
# 发起请求
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))