简体   繁体   English

当请求access_token时,Instagram收到400错误的请求

[英]Instagram get 400 bad request when request the access_token

I'm following Instagram's instruction to learn how to get access_token. 我正在按照Instagram的指示学习如何获取access_token。

I stucked in the step 3. I have tried to use curl and python script to connect, but both failed. 我陷入了步骤3。我尝试使用curl和python脚本进行连接,但是都失败了。

Here is my curl code: 这是我的卷曲代码:

curl -F 'client_id=MY_CLIENT_ID’ \ 
-F 'client_secret=MY_CLIENT_SECRET’ \ 
-F 'grant_type=authorization_code’ \ 
-F 'redirect_uri=http://localhost' \ 
-F 'code=MY_CODE' \
https://api.instagram.com/oauth/access_token

The return is showed as below 收益显示如下

curl: (6) Couldn't resolve host ' '
curl: (6) Couldn't resolve host ' '
curl: (6) Couldn't resolve host ' '
curl: (1) Protocol " https" not supported or disabled in libcurl

But curl I used already support ssl . 但是我使用的curl已经支持ssl

Then I tried python, here is the code(Thanks for @avinash showing me the single quote problem, but still failed) 然后我尝试了python,这是代码(感谢@avinash向我展示了单引号问题,但仍然失败)

url = 'https://api.instagram.com/oauth/access_token'
values = {
    "client_id"     :   "MY_CLIENT_ID",
    "client_secret" :    "MY_CLIENT_SECRET",
    "grant_type" : "authorization_code",
    "redirect_uri" : "http://localhost",
    "code" : "MY_CODE"
}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()

Just get the error urllib2.HTTPError: HTTP Error 400: BAD REQUEST . 只需获取错误urllib2.HTTPError: HTTP Error 400: BAD REQUEST

Can anyone help me figure out what's wrong here? 谁能帮我弄清楚这里出了什么问题? Thanks! 谢谢!

You may take a look at this article .It explains that you may be trying to send value as a string of json, not as a dictionary that's converted to a string. 您可以看一下这篇文章。它解释说您可能试图将值作为json字符串发送,而不是作为转换为字符串的字典发送。 If it is the case please replace all single quotes with double quotes 如果是这种情况,请用双引号替换所有单引号

values = {
    "client_id"     :   "MY_CLIENT_ID",
    "client_secret" :    "MY_CLIENT_SECRET",
    "grant_type" : "authorization_code",
    "redirect_uri" : "http://localhost",
    "code" : "MY_CODE"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试访问JSON时,BAD REQUEST 400 - BAD REQUEST 400, when trying to access JSON 当我尝试请求OAuth access_token时,我得到:TypeError:encode()参数1必须是字符串,而不是None - When trying to request for OAuth access_token I get: TypeError: encode() argument 1 must be string, not None Google Oauth2中的400错误的访问令牌请求 - 400 Bad Request in Google Oauth2 for access token 在Google处使用访问令牌交换授权码:400错误请求 - Exchanging authorization code with access token @ Google: 400 Bad Request Python 带身份验证的请求 (access_token) - Python request with authentication (access_token) http://localhost:8000/token/ 400(错误请求) - http://localhost:8000/token/ 400 (Bad Request) 带套接字的 Python GET 请求 - 400 错误请求 - Python GET request with sockets - 400 Bad request 从 Spotify API 交换访问令牌的代码时,为什么我不断收到 400 错误请求错误? - Why do I keep getting a 400 Bad Request Error when exchanging code for access token from Spotify API? 使用Python请求登录时获得HTTP 400错误请求 - Get HTTP 400 Bad Request when login using Python requests 我无法使用请求 Python 登录 Instagram(错误请求 400) - I cant login instagram with requests Python (bad request 400)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM