Tôi đang sử dụng API biểu đồ Facebook trên Google App Engine. Tôi đã có thể tìm nạp tất cả thông tin cơ bản từ người dùng. Tuy nhiên, khi tôi cố gắng tìm nạp bất kỳ thông tin người dùng nào yêu cầu sự cho phép, email cho exemple, nó luôn xuất hiện là None. Tôi đã theo toàn bộ hướng dẫn có sẵn tại developers blog.Làm cách nào để nhận email người dùng bằng API biểu đồ Facebook trong GAE Python?
Dưới đây là mã của tôi:
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
Và dưới đây là mẫu/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 %}
Có điều gì sai? Có cách nào khác để nhận email người dùng không?
Thử thêm một số đầu ra gỡ lỗi của cấu hình bạn nhận được từ FB và xem email có ở đó không. Khi hộp thoại ủy quyền FB xuất hiện, nó có bao gồm quyền email không? – cope360