使用 Python 的 Instagram 客户端身份验证

Instagram Client Side Authentication using Python

我目前正在做一个瓶子项目,并将使用 Instagram api。我希望使用客户端身份验证,但是我遇到了访问令牌的问题,因为它没有 returns 作为参数。

我在这里提出请求:

https://api.instagram.com/oauth/authorize/?client_id=client_id&redirect_uri=redirect_uri&response_type=token&scope=basic+follower_list

应用程序正确重定向到令牌页面,我什至可以在 url 中看到令牌。但是当我尝试解析它时,它是空的。

@route('/oauth_callback')
def success_message():

token = request.GET.get("access_token")

print token.values()
return "success"

token.values() returns 一个空列表。

ps:请记住,当我尝试对服务器端身份验证执行相同的操作时,我可以成功获取代码并将其交换为令牌。

一旦你向 Instagram 查询 api 你一定会收到以下回复?

http://your-redirect-uri#access_token=ACCESS-TOKEN

# 之后的部分称为 片段 而不是 query_string参数,您无法在 Bottle 的服务器端检索该信息。

实际获取碎片,使用bottle.request.urlparts

urlparts

The url string as an urlparse.SplitResult tuple. The tuple contains (scheme, host, path, query_string and fragment), but the fragment is always empty because it is not visible to the server.

使用 SDK,最好使用服务器端操作 -> https://github.com/facebookarchive/python-instagram

如果你愿意采用这种方法,那么管理一个 JavaScript 来解析 access-token 然后发布到你的瓶子 api 供你消费,我不建议这样做...

来自https://instagram.com/developer/authentication/

Client-Side (Implicit) Authentication

If you are building an app that does not have a server component (a purely javascript app, for instance), you will notice that it is impossible to complete step three above to receive your access_token without also having to store the secret on the client. You should never pass or store your client_id secret onto a client. For these situations there is the Implicit Authentication Flow.