Twitcasting API - Implicit Grant Type (OAuth2)
使用ライブラリ: PyTwitcasting
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from pytwitcasting.utils import get_access_token_prompt_implicit from pytwitcasting.api import API import os import configparser def create_ini(): client_id = 'cimatest.709e2be465414f56bc856123bf65e16afb5e3904ed1e5161d2c008fbdf00afe2' access_token = get_access_token_prompt_implicit(client_id=client_id) config = configparser.ConfigParser() config['client'] = { 'id': client_id } config['user'] = { 'access_token': access_token } with open('config.ini', 'w') as f: config.write(f) def get_access_token(): config = configparser.ConfigParser() config.read('config.ini') return config['user']['access_token'] if __name__ == '__main__': if not os.path.isfile('config.ini'): create_ini() print('created config.ini') user_id = 'c:imatest' api = API(access_token=get_access_token()) d = vars(api.get_user_info(user_id)) for t in sorted(d.items()): print('{}: {}'.format(t[0], t[1]))
Opened **** Enter the URL you were redirected to: 既存のブラウザ セッションで開いています。 **** created config.ini _api: <pytwitcasting.api.API object at 0x7fc68faaf5c0> _json: {'profile': 'これはテストプロフィール。', 'supporter_count': 0, 'image': 'http://twitcasting.tv/img/twitcas_bigger_3.png', 'name': 'A test', 'created': 0, 'screen_id': 'c:imatest', 'last_movie_id': None, 'id': 'c:imatest', 'supporting_count': 0, 'level': 1, 'is_live': False} created: 1970-01-01 09:00:00 id: c:imatest image: http://twitcasting.tv/img/twitcas_bigger_3.png is_live: False last_movie_id: None level: 1 name: A test profile: これはテストプロフィール。 screen_id: c:imatest supporter_count: 0 supporting_count: 0