[英]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.