Search code examples
facebook-graph-apipyramid

Velruse Facebook profile has no email


I'm using Pyramid and Velruse to authenticate users, and I just saw an exception when a user tried to authenticate through Facebook. The error is a KeyError: 'verifiedEmail' here:

// Callback view for Facebook.
@view_config(                                                                   
    context='velruse.AuthenticationComplete',                                   
)                                                                           
def authenticate_complete(request):                                             
    context = request.context
    email = context.profile['verifiedEmail']
    ...

Looking at the Velruse code it seems that a Facebook profile may not contain email information, although Facebook states that the email is information approved by default for my app.

Where do things go wrong here? Is this a Facebook user setting which I may have to handle, or is something missing from my code?


Solution

  • Facebook states that the email is information approved by default for my app

    The email scope/permission does not require login review, but you do have to request it as part of the authentication flow for the user to be prompted to share it with your application.

    The user may reject your request for access to their email. Additionally, some users log in with a cell phone number and may not have an email address on file with Facebook at all.

    Short answer: some users won't give or have an email. Your application needs to account for this.