[英]Python - Get Instagram API Access Token
I am trying to call the Instagram Basic API to get the user info.我正在尝试调用 Instagram Basic API 以获取用户信息。 However, I need to fetch the access token first for the authentication.
但是,我需要先获取访问令牌进行身份验证。
I have implemented the code for getting the same in python but I am only able to fetch the re-direct uri.我已经实现了在 python 中获得相同的代码,但我只能获取重定向 uri。 Now, as a manual step we execute that uri on browser and get the code from the url.
现在,作为手动步骤,我们在浏览器上执行该 uri 并从 url 获取代码。
But in case of programming how can I get the access token?但是在编程的情况下,我怎样才能获得访问令牌?
In below code: I am getting error在下面的代码中:我收到错误
from instagram_basic_display.InstagramBasicDisplay import InstagramBasicDisplay
from flask import request
instagram_basic_display = InstagramBasicDisplay(app_id='5163403347035424', app_secret='80473de6ad506c837969e03b8ccdb4cb', redirect_url='https://mycogito.me/')
print(instagram_basic_display.get_login_url()) # Returns login URL you need to follow
code = request.args.get('code')
print(code)
Error错误
Traceback (most recent call last):
File "D:\Work Backup\Development\Workspaces\python\SocialMedia\src\com\social\media\HelloWorld.py", line 9, in <module>
https://api.instagram.com/oauth/authorize?client_id=5163403347035424&redirect_uri=https%3A%2F%2Fmycogito.me%2F&scope=user_profile%2Cuser_media&response_type=code
code = request.args.get('code')
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\werkzeug\local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\werkzeug\local.py", line 306, in _get_current_object
return self.__local()
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\globals.py", line 38, in _lookup_req_object
raise RuntimeError(_request_ctx_err_msg)
RuntimeError: Working outside of request context.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.