1

I'm following Instagram's instruction to learn how to get access_token.

I stucked in the step 3. I have tried to use curl and python script to connect, but both failed.

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.

Then I tried python, here is the code(Thanks for @avinash showing me the single quote problem, but still failed)

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.

Can anyone help me figure out what's wrong here? Thanks!

AdaroMu
  • 166
  • 2
  • 8
  • 1
    Why don't you use instagram's Python library? That takes care of this for you. – Daniel Roseman Mar 27 '15 at 07:31
  • @DanielRoseman Actually I just want to test if I wrote wrong curl command since python script is easy to write. I'm not planning to use python in my development. And I'm really curious about what I did wrong here. – AdaroMu Mar 27 '15 at 07:42

1 Answers1

0

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. 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"
}
Community
  • 1
  • 1
avinash pandey
  • 1,321
  • 2
  • 11
  • 15