ccoenraets / OpenFB

Micro-library that lets you integrate browser and Cordova apps with Facebook with no plugin or SDK dependency.
MIT License
505 stars 231 forks source link

Fetching email address #127

Open jester6san opened 6 years ago

jester6san commented 6 years ago

I am running this in my app built with phonegap:

`function handleFbLogin() { openFB.login( function(response){ alert(JSON.stringify(response)); if (response.status == 'connected') { getUsersData(response.authResponse.accessToken); }else{ // Login cancelled by the user. alert('Login With Facebook Cancelled'); } }, { scope: 'email' // for more permissions see https://developers.facebook.com/docs/facebook-login/permissions } ); }

function getUsersData(token) { openFB.api({ path: "/me?fields=email&access_token='"+token+"'", //path: '/me?access_token=' + token, success: function(f) { // f is an object / { id: "123456789", // Facebook User Id birthday: "06/10/1394", email: "useremail@gmail.com", // Facebook User Email first_name: "Mark", // Firstname gender: "male", // Gender last_name: "openfb", // Last name link: "https://www.facebook.com/app_scoped_user_id/123456789/", locale: "en_US", name: "Mark openfb", timezone: 1, updated_time: "2014-04-15T60:48:21+0000", verified: true, // If user is verified website: "openfb.com" } / alert(JSON.stringify(f)); // Mark openfb }, error: function(e) { alert(JSON.stringify(e)); } }); }`

It says the token is invalid or malformed no matter what I do :/ How do I pass the access token correctly and why isn't that documented?