I am creating a website in PHP and i want to use login with Facebook in my website. I have created an app ID in Facebook developer. Facebook login is working but i want to retrieve email id which is used on Facebook login.
here is my JavaScript code :
$facebook.api("/me").then(
function(response) {
console.log(response);
alert("Welcome " + response.email);
},
function(err) {
alert("Please log in");
});
Output:
response.email is undefined.
On console log i am getting an object like object {name:"xxx",id:"111"}
How to retrieve Facebook login email id?
Facebook provides all the details which are public or approved by facebook. So in that case you cannot get email-id everytime.
Suppose one user is not using email in his account or email is private, than you cannot get his email-id.
Regards.
In order to get the user email, you will need to follow these steps:
Set the email permission for your app.
When you call $facebook.api("/me") try calling like this $facebook.api("/me?fields=id,name,email") by doing this you should get the email of the logged in person.
Note:
Even if you have set the email permission some user sign up for facebook using their mobile no. as username or some user want their email to be private by setting privacy, so, in that case you won't get the get the user email.
So in case you want to save user in database for future reference work on id as this is the unique identifier for that user.
In case you want user email and if fb doesn't provide it you can ask explicitly.
Hope this will help you.
Related
The URL Im pointing to is:
const res = await fetch(
`https://graph.facebook.com/v12.0/me?locale=en_US&fields=email,picture.width(720).height(720)&access_token=${accessToken}`
)
I am using this endpoint to get the user information but the email is not returned even the version used in the URL is the latest v12.0. Interestingly the email of only the administrator account is been returned.
I have assigned Advanced Access to both email & public_profile.
Is something missing here?
Thanking in advance :)
Actually, the reason why some of the accounts were not returning the email key in the object was that they do not have any primary email setup for their Facebook account inside the General Account Settings.
The users were using their phone numbers or username to log in on Facebook.
That's why when they were logging in to my application, the Facebook Graph API couldn't get the email from their accounts, and ultimately I couldn't get their email addresses in the response object.
I need to create a cookie with clientID(need email to create it), when customer register/login on shopify shop.
How can I get email during register/login? Is it possible to get it from Customer object(js injected via script-tag) and how? The only possible way I see at the moment is to create onclick event on register/login and catch customer e-mail from post?
CustomerId (__st.cid) won't work for me.
You have access to the {{customer.email}} attribute.
Once the user register he is redirected to the account page and he is logged in already.
So on the account page you just create the cookie by passing the customer.email to a script and set it there.
I am trying to implement Facebook login SPA. I am using the JavaScript SDK for the login. Fb authorized the user and token is received. Token is send to the web API. When API try to fetch the data from the token only Facebook id and name return from the Facebook graph api. Even though I have set the scope for the different data in java script sdk. If i fetch the data using javascript sdk. In that case i am getting the complete data whatever in the scope.
I think your asking "why am I not getting all the data I requested?". If so the most common reason is because permissions aren't set. For instance if the user grants permission to "public_profile" then Facebook will authorize your app to obtain every field that that the "public_profile" permission permits, in this case the following:
id, name, first_name, last_name, age_range, link, gender, locale, picture, timezone, updated_time, verified
obtained via
FB.api('/me',
'GET',
{"fields":"id,name"}, //any of the other fields here
function(response) {
// Insert your code here
} );
however if added 'email' in as a field then the Facebook would return everything except the 'email' because there a permission specifically for granting access to the users email called email. You can see what permissions enable what data returns at https://developers.facebook.com/docs/facebook-login/permissions
and you can test it at https://developers.facebook.com/tools/explorer. I hope that's what you where trying to say in your question. Cheers!
I'm building a Meteor app for contracts. A signed in user can create a contract. But I'd like for them to be able to send a contract to another party, who can view the contract without signing up or creating an account. The problem is that, even if the URL is long and random, www.example.com/docs/bM7GjrRq1wABYdxws3 -- I'm not sure it is private enough -- because maybe all these contracts could be easily crawled or end up in search like this.
I'd like the creator of the contract to set a password that can be emailed to the other party along with the link to the contract. Before the party can view the contract, they need to enter the password.
My solution is to allow a user to password protect the page (but without a username/email). But I'm not sure how to do it. How can I password protect a page with a password set by a user?
You could save password within the page object on mongodb.
Then when he creates or edit the page, he might choose to share publicly or with password.
The publish method could look somewhat like this.
Meteor.publish("page", function (){
if (!this.userId) {
return Pages.find({
_id: Session.get("pageId"),
private: true,
password: Session.get("pagePassword")
});
} else {
// code for logged in users
}
});
Of course it's a good idea to store a hash for the password and compare to the hash the user entered, instead of storing the raw password.
is there ant way to get Facebook user Id by passing the email and password of the user through a graph API....what i want to do is,i want to get the profile details of a particular user..if we know the user id then the details of the particular user can be obtained by the GRAPH API..
https://graph.facebook.com/ID
but i don't know how to get the Facebook user id.....please help me out....
I'm using JavaScript and html5 for mobile applications..both android and ios..and the IDE's are APPMOBI and PHONEGAP
You can try getting an access token by logging in using the username and password, then calling https://graph.facebook.com/me and getting the id field. I don't think there's a direct way of getting an id through the API just using the username and password without getting an access token for that user, which would require that the user accept your appId.