LoginSignup
0
2

More than 3 years have passed since last update.

APIを使用し、PythonからInstagramの情報を取得する方法

Posted at

APIを使用し、PythonからInstagramの情報を取得する方法

instagram.py

from instagram_basic_display.InstagramBasicDisplay import InstagramBasicDisplay

instagram_basic_display = InstagramBasicDisplay(app_id ='********', app_secret='**********', redirect_url='https://localhost:8080/')

#ig_codeにはredirect_urlに記載されているcodeが入る
auth_token = instagram_basic_display.get_o_auth_token(ig_code)

#auth_tokenから取得したaccess_tokenが代入される
instagram_basic_display.set_access_token(auth_token['access_token'])
ig_profile = instagram_basic_display.get_user_profile()

ターミナルでの実行

#python manage.py shell を実行
>>>from instagram_basic_display.InstagramBasicDisplay import InstagramBasicDisplay
>>>instagram_basic_display = InstagramBasicDisplay(app_id ='********', app_secret='**********', redirect_url='https://localhost:8080/')

#ig_codeにはredirect_urlに記載されているcodeが入る
>>>ig_code =''
>>>auth_token = instagram_basic_display.get_o_auth_token(ig_code)
>>>auth_token
#abcdefgは例、実際はもっと量が多い
{'access_token': 'abcdefg', 'user_id': 12345678912345678}

>>>instagram_basic_display.set_access_token('abcdefg')
>>>ig_profile = instagram_basic_display.get_user_profile()
>>>ig_profile
{'account_type': 'PERSONAL', 'id': '12345678912345678', 'media_count': 1, 'username': 'admin.test'}

*これらを行う前にfacebook for developers でinstagram_basic_displayの設定を行う必要がある
facebook for developers

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2