どのように私はGAE PythonでのFacebookグラフAPIを使用して、ユーザーの電子メールを得るのですか?

StackOverflow https://stackoverflow.com/questions/4005963

質問

私はGoogle App Engineの上のFacebookグラフAPIを使用しています。私は、ユーザーからのすべての基本的な情報を取得することができました。私はexempleの許可、電子メールを必要とするすべてのユーザー情報を取得しようとしたときにしかし、それは常にNoneと表示されます。私は開発者で全体のチュートリアルで利用できるがのブログに続いてきました。

ここに私のコードです:

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

:ここで

とは、テンプレート/ HTMLです

<fb:login-button autologoutlink="true" perms="email"></fb:login-button>

{% if current_user %}
  <p><a href="{{ current_user.profile_url }}"><img src="http://graph.facebook.com/{{ current_user.id }}/picture?type=square"/></a></p>
  <p>Hello, {{ current_user.name|escape }}</p>
  <p>email: {{ current_user.email }} </p>
{% endif %}
そこに何かが間違っていますか?ユーザーの電子メールを取得するための他の方法はありますか?

役に立ちましたか?

解決 2

だけは facebook.py と使用してあきらめました facebookoauth.py と自分のOAuthを作った2 UrlFetchのを使用してクライアント。 Facebookのドキュメントでの「Webアプリケーションでの認証ユーザーのを参照してください。

また、私はscope='email'https://graph.facebook.com/oauth/authorize?への要求にhttps://graph.facebook.com/oauth/access_token?を入れます。

scroll top