Jeune
Jeune

Reputation: 3548

Problem with Facebook OAuth on Google Appengine

I am using the "Server Side" flow to get a user's permissions to access some information using Python on Google Appengine.

I am able to get the server generated code from Facebook after the user clicks on the "Allow" button.

However when I get the access token, I run into the following error:

Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/init.py", line 515, in call handler.get(*groups) File "/base/data/home/apps/finisherph/1.348502373491720746/controllers.py", line 21, in get data = urllib2.urlopen(access_token_url)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 124, in urlopen return _opener.open(url, data) File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 387, in open response = meth(req, response) File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 498, in http_response 'http', request, response, code, msg, hdrs) File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 425, in error return self._call_chain(*args) File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 506, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 400: Bad Request

Here's the code in my controller where the response from facebook goes after user clicks on the "Allow" button. It's still a hack so the code is a little bit dirty. Still trying to make it work.

class Register(webapp.RequestHandler):
            def get(self):
                code=self.request.get('code')
                logging.debug("code: "+code)
                accesst_url=["https://graph.facebook.com/oauth/access_token?"]
                accesst_url.append("client_id=CLIENT_ID&")
                import urllib         
                accesst_url.append(urllib.urlencode
                    ({'redirect_uri':'http://my.website.com/register/facebook/'}))
                accesst_url.append('&')
                accesst_url.append("client_secret=CLIENT_SECRET&")
                accesst_url.append("".join(["code=",str(code)]))
                logging.debug(accesst_url)
                access_token_url="".join(accesst_url)
                logging.debug(access_token_url)
                import urllib2
                data = urllib2.urlopen(access_token_url)
                    ...
                    ...

The error occurs here:

data = urllib2.urlopen(access_token_url)

when I copy and paste the access_token_url from my logs, I get the following error:

{ "error": { "type": "OAuthException", "message": "Error validating verification code." } }

What am I missing here?

Upvotes: 0

Views: 1760

Answers (1)

Senthil Kumaran
Senthil Kumaran

Reputation: 56881

It looks like you are trying to access the access_token as url, which is not quite right.

Here is an example which illustrates how OAuth authentication via FB is done over GAE.

Upvotes: 1

Related Questions