"Missing redirect_uri parameter" response from Facebook with Python/Django
Asked Answered
W

1

7

This is probably a very dumb question, but I have been staring at this for hours and can't find what I'm doing wrong.

I am trying to use Python to authenticate with the Facebook API, but am having issues requesting a user access token. After receiving a code, I make a request to https://graph.facebook.com/oauth/access_token like so:

conn = httplib.HTTPSConnection("graph.facebook.com")
params = urllib.urlencode({'redirect_uri':request.build_absolute_uri(reverse('some_app.views.home')),
                           'client_id':apis.Facebook.app_id,
                           'client_secret':apis.Facebook.app_secret,
                           'code':code})
conn.request("GET", "/oauth/access_token", params)
response = conn.getresponse()
response_body = response.read()

In response, I receive

{"error":{"message":"Missing redirect_uri parameter.","type":"OAuthException","code":191}}

Any ideas what could be going wrong? I have already verified that the redirect_uri that is being passed is on the app domain, but could it be an issue that this is being hosted locally and that domain is just redirected to localhost by my hosts file?

Thanks for your help!

edit:

I got this working using the requests library:

params = {'redirect_uri':request.build_absolute_uri(reverse('profiles.views.fb_signup')),
                           'client_id':apis.Facebook.app_id,
                           'client_secret':apis.Facebook.app_secret,
                           'code':code}

r = requests.get("https://graph.facebook.com/oauth/access_token",params=params)

However, I would still prefer to be dependent on a library when this should be supported natively without too much difficulty. Maybe this is asking too much...

Wedurn answered 18/6, 2012 at 1:37 Comment(3)
If your localhost is set up correctly it should work. Facebook will check if the redirection worksSystemize
That's what I thought. Any ideas what else could be going wrong?Wedurn
mmm, on facebook developers go to your application. The redirect uri hast to match the application uriSystemize
R
2

In your first example (the one using HTTPSConnection), you are passing params in the body of the request:

conn.request("GET", "/oauth/access_token", params)

This is incorrect (GET requests should have no body). Instead, parameters should be passed as the query string part of the URL:

conn.request("GET", "/oauth/access_token?" + params) 
Ralleigh answered 12/10, 2013 at 5:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.