Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get user email using Facebook Graph API in GAE Python?
    primarykey
    data
    text
    <p>I'm using Facebook Graph API on Google App Engine. I was able to fetch all the basic info from an user. However when I tried to fetch any user info that requires permission, email for exemple, it always appears as None. I've followed the whole tutorial available at the <a href="http://developers.facebook.com/docs/guides/web" rel="noreferrer">developers blog</a>.</p> <p>Here's my code:</p> <pre><code>class User(db.Model): id = db.StringProperty(required=True) created = db.DateTimeProperty(auto_now_add=True) updated = db.DateTimeProperty(auto_now=True) name = db.StringProperty(required=True) email = db.StringProperty(required=True) profile_url = db.StringProperty(required=True) access_token = db.StringProperty(required=True) class BaseHandler(webapp.RequestHandler): """Provides access to the active Facebook user in self.current_user The property is lazy-loaded on first access, using the cookie saved by the Facebook JavaScript SDK to determine the user ID of the active user. See http://developers.facebook.com/docs/authentication/ for more information. """ @property def current_user(self): if not hasattr(self, "_current_user"): self._current_user = None cookie = facebook.get_user_from_cookie( self.request.cookies, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET) if cookie: # Store a local instance of the user data so we don't need # a round-trip to Facebook on every request user = User.get_by_key_name(cookie["uid"]) if not user: graph = facebook.GraphAPI(cookie["access_token"]) profile = graph.get_object("me") user = User(key_name=str(profile["id"]), id=str(profile["id"]), name=profile["name"], email=profile["email"], profile_url=profile["link"], access_token=cookie["access_token"]) user.put() elif user.access_token != cookie["access_token"]: user.access_token = cookie["access_token"] user.put() self._current_user = user return self._current_user </code></pre> <p>And here is the template/HTML:</p> <pre><code>&lt;fb:login-button autologoutlink="true" perms="email"&gt;&lt;/fb:login-button&gt; {% if current_user %} &lt;p&gt;&lt;a href="{{ current_user.profile_url }}"&gt;&lt;img src="http://graph.facebook.com/{{ current_user.id }}/picture?type=square"/&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Hello, {{ current_user.name|escape }}&lt;/p&gt; &lt;p&gt;email: {{ current_user.email }} &lt;/p&gt; {% endif %} </code></pre> <p>Is there something wrong? Is there other way to get user email?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload