title: Problem with Facebook OAuth on Google Appengine
body: <p>I am using the "Server Side" flow to get a user's permissions to access some information using Python on Google Appengine. </p>
  
  <p>I am able to get the server generated code from Facebook after the user clicks on the "Allow" button. </p>
  
  <p>However when I get the access token, I run into the following error: </p>
  
  <blockquote>
    <p>Traceback (most recent call last):<br>
    File
    "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/<strong>init</strong>.py",
    line 515, in <strong>call</strong>
        handler.get(*groups)   File "/base/data/home/apps/finisherph/1.348502373491720746/controllers.py",
    line 21, in get
        data = urllib2.urlopen(access_token_url)<br>
    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</p>
  </blockquote>
  
  <p>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. </p>
  
  <pre><code>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&amp;")
                  import urllib         
                  accesst_url.append(urllib.urlencode
                      ({'redirect_uri':'http://my.website.com/register/facebook/'}))
                  accesst_url.append('&amp;')
                  accesst_url.append("client_secret=CLIENT_SECRET&amp;")
                  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)
                      ...
                      ...
  </code></pre>
  
  <p>The error occurs here: </p>
  
  <pre><code>data = urllib2.urlopen(access_token_url)
  </code></pre>
  
  <p>when I copy and paste the access_token_url from my logs, I get the following error: </p>
  
  <blockquote>
    <p>{    "error": {
          "type": "OAuthException",
          "message": "Error validating verification code."    } }</p>
  </blockquote>
  
  <p>What am I missing here? </p>