使用python获取Instagram访问令牌

时间:2018-06-29 14:24:50

标签: python python-3.x instagram instagram-api

使用Flask和python-instagram库获取访问令牌时出现错误。任何想法将不胜感激

尝试获取授权网址时出现错误:

Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\flask\app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Python37\lib\site-packages\flask\app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Python37\lib\site-packages\flask\app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Python37\lib\site-packages\flask\_compat.py", line 35, in reraise
    raise value
  File "C:\Python37\lib\site-packages\flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Python37\lib\site-packages\flask\app.py", line 1816, in full_dispatch_request
    return self.finalize_request(rv)
  File "C:\Python37\lib\site-packages\flask\app.py", line 1831, in finalize_request
    response = self.make_response(rv)
  File "C:\Python37\lib\site-packages\flask\app.py", line 1957, in make_response
    'The view function did not return a valid response. The'
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

这是失败的代码:

  try:
    url = api.get_authorize_url(scope=None)
    redirect(url)
  except InstagramAPIError as e:
    print(e)

背景:我是python和Web开发的新手,我认为我可以通过创建一个简单的应用程序来学习,该应用程序可以根据标签等不同的搜索条件提取IG图片。任何帮助都会有用。

1 个答案:

答案 0 :(得分:0)

TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

该错误实际上告诉了您所有需要了解的内容。您需要在make_response()中返回一些内容(假设url变量正确无误,并且您有一条路由)。

  try:
    url = api.get_authorize_url(scope=None)
    return redirect(url_for(url))
  except InstagramAPIError as e:
    print(e)

您可以阅读有关此here的更多信息。