Twitterの投票機能 投票を発行(対策された?, あとで修正します)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def StartPoll(): | |
from requests_oauthlib import OAuth1Session | |
#端末向けの公式アプリ系のCK/CSじゃないとダメ(デフォルトでTwitter for iPhone) | |
CK = 'IQKbtAYlXLripLGPWd0HUA' | |
CS = 'GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU' | |
AT = '' | |
AS = '' | |
auth = OAuth1Session(CK, CS, AT, AS) | |
#はじめに投票を発行する | |
url = 'https://caps.twitter.com/v2/cards/create.json' | |
#うまくパラメーターをつくれないですごめんなさい | |
"""params = { | |
"twitter:api:api:endpoint": "1", | |
"twitter:card": "poll4choice_text_only", #選択肢の個数に応じてpollnに指定(n=2,3,4) | |
"twitter:long:duration_minutes": 8944, #有効時間(秒単位, 7日まで) | |
"twitter:string:choice1_label": "選択肢1", | |
"twitter:string:choice2_label": "選択肢2", | |
"twitter:string:choice3_label": "選択肢3",#選択肢3,4はオプションなので不要な場合には削る | |
"twitter:string:choice4_label": "選択肢4" | |
} | |
params = 'card_data=%7B%22'+urllib.urlencode(params)+'%22%7D&send_error_codes=1' | |
""" | |
params = "card_data=%7B%22twitter%3Astring%3Achoice3_label%22%3A%22test4%22%2C%22twitter%3Aapi%3Aapi%3Aendpoint%22%3A%221%22%2C%22twitter%3Astring%3Achoice1_label%22%3A%22test2%22%2C%22twitter%3Acard%22%3A%22poll4choice_text_only%22%2C%22twitter%3Along%3Aduration_minutes%22%3A8944%2C%22twitter%3Astring%3Achoice4_label%22%3A%22test5%22%2C%22twitter%3Astring%3Achoice2_label%22%3A%22test3%22%7D&send_error_codes=1" | |
req = auth.post(url, params=params) | |
card_uri = json.loads(req.text)['card_uri'] | |
time.sleep(3) | |
url = 'https://api.twitter.com/1.1/statuses/update.json' | |
params = { | |
"card_uri": card_uri, | |
"status": u"114514", | |
"cards_platform": "iPhone-13", | |
"contributor_details": 1, | |
"include_cards": 1 | |
} | |
req = auth.post(url, params=params) | |
print req.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment