沙盒中的 OAuthPermissionsException Instagram API

OAuthPermissionsException Instagram API in Sandbox

我正在尝试使用 Instagram API 访问与标签(我们称之为“X”)相关的数据。我直接从 Python 和浏览器尝试了 运行 它,但得到了同样的错误:

{u'meta': {u'code': 400, u'error_type':u'OAuthPermissionsException',
u'error_message': u'This request requires scope=public_content, but this
access token is not authorized with this scope. The user must re-authorize
your application with scope=public_content to be granted this permissions.'}}

这是我编写的简单 Python 代码,以便首先使其工作:

import requests

access_token = 'zzzzzzzzzzzzz'
parameters = {"q": "X",
              "scope": "public_content",
              "access_token": "zzzzzzzzzzzzz"}

response = requests.get("https://api.instagram.com/v1/tags/search",
                        params=parameters)
insta_posts = response.json()

我使用的是正确的 URL 沙盒吗?我阅读了 Instagram API 文档,Sandbox 中的应用程序不需要任何类型的批准即可更改范围。

此外,该应用程序仅获得 Sandbox 授权:

Screen Capture of Application Defined in Instagram API

我明白是怎么回事了。首先需要更改应用程序的授权范围。我是这样做的:

从您的浏览器执行:

https://api.instagram.com/oauth/authorize/?client_id=CLIENTID&redirect_uri=REDIRECT-URI&response_type=code&scope=SCOPE

只需要为大写的单词插入数据

完成后,该应用程序将获得该范围的授权。

因为我已经有了访问令牌,所以我不需要执行第 2 步和第 3 步。

这是一个很好的例子:

https://www.instagram.com/oauth/authorize?client_id=b23670e258o0fmk334jfu287c9f9953&redirect_uri=http://127.0.0.1:5000&response_type=code&scope=basic+public_content+follower_list+comments+relationships+likes

只需在 URL:

末尾添加作用域参数
&scope=basic+public_content+follower_list+comments+relationships+likes