Facebook Graph API, how to get users email?
The only way to get the users e-mail address is to request extended permissions on the email field. The user must allow you to see this and you cannot get the e-mail addresses of the user's friends.
http://developers.facebook.com/docs/authentication/permissions
You can do this if you are using Facebook connect by passing scope=email in the get string of your call to the Auth Dialog.
I'd recommend using an SDK instead of file_get_contents as it makes it far easier to perform the Oauth authentication.
How to get users email and fd id using facebook login with graph api
The same way you access name. i.e
response.email
and response.id
but to fetch email address you must have the permission to access it.
Add scope="email"
to your FB Login Button.
[EDIT]
function login() {
FB.login(function(response) {
if (response.authResponse) {
// connected
testAPI();
} else {
// cancelled
}
}, { scope: 'email' });
}
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.' + ' Email: ' + response.email + ' Facebook ID: ' + response.id);
});
}
Here's a good tutorial for beginners: http://www.loginworks.com/technical-blogs/404-working-with-facebook-javascript-sdk
how to get user email in facebook graph api
You have to authorize users with the email
permission:
$dialog_url = 'http://www.facebook.com/dialog/oauth?client_id=' . FACEBOOK_APP_ID . '&redirect_uri=' . $callback_url . '&scope=email';
Source: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
How Can I Get User Email With Facebook Login Button?
Accualy i need full code example. Because i think facebook documents are complicated. (Or for me) And I found a solution internet. Here you can see below;
FB Login Button:
<div class="fb-login-button" data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="true" data-scope="email,user_hometown,user_birthday,user_education_history,user_website,user_work_history"></div>
FB Sdk initialize:
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/tr_TR/sdk.js#xfbml=1&version=v2.4&appId=***********";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Getting other user information:
window.fbAsyncInit = function() {
FB.init({
appId : '************', // Set YOUR APP ID
channelUrl : 'http://hayageek.com/examples/oauth/facebook/oauth-javascript/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
version : 'v2.4',
oauth : true
});
FB.Event.subscribe('auth.authResponseChange', function(response)
{
if (response.status === 'connected')
{
console.log("<br>Connected to Facebook");
//SUCCESS
FB.api('/me', { locale: 'tr_TR', fields: 'name, email,birthday, hometown,education,gender,website,work' },
function(response) {
console.log(response.email);
console.log(response.name);
console.log(response.gender);
console.log(response.birthday);
console.log(response.hometown);
console.log(response.education);
console.log(response.website);
console.log(response.work);
}
);
}
else if (response.status === 'not_authorized')
{
console.log("Failed to Connect");
//FAILED
} else
{
console.log("Logged Out");
//UNKNOWN ERROR
}
});
};
how to get user facebook email id (that is used for login)
Given that revealing a person's email without consent would be a violation of that person's privacy, this is not possible.
The only way to get access to this data would be to have the user grant the email
permission to your app, at which point you could use /me?fields=email
.
How to get Users Email Id in Facebook application using PHP?
You can get the Email Address, directly without using the FQL.
// initialize facebook
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET));
$session = $facebook->getSession();
if ($session) {
try {
$fbme = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
else
{
echo "You are NOT Logged in";
}
//getting the login page if not signned in
if (!$fbme) {
$loginUrl = $facebook->getLoginUrl(array('canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'email,user_birthday,publish_stream',
'next' => CANVAS_PAGE,
'cancel_url' => CANVAS_PAGE ));
echo '<fb:redirect url="' . $loginUrl . '" />';
} else {
// $fbme is valid i.e. user can access our app
echo "You can use this App";
}
// getting the profile data
$user_id = $fbme[id];
$name=$fbme['name'];
$first_name=$fbme['first_name'];
$last_name=$fbme['last_name'];
$facebook_url=$fbme['link'];
$location=$fbme['location']['name'];
$bio_info=$fbme['bio'];
$work_array=$fbme['work'];
$education_array=$fbme["education"];
$email=$fbme['email'];
$date_of_birth=$fbme['birthday'];
This code worked for me..and i go all the information needed with the Email ID.
NOTE: User has to allow us to get their Information during the Approval of Application.
Get Email address of Facebook user from post comments
You just need to use the correct syntax for the Field Expansion that you’re already making use of:
feed?fields=message,id,description,created_time,from,comments{from,email, id,created_time,message},story
The email of the comment creator would be a “property” of the from
structure, so you can use
/feed?fields=comments{from{id,name,email},…}
to get the email of people who commented (and granted your app permission to read their e-mail upfront.)
Related Topics
Cast Value of Type 'Uitableviewcell' to Custom Cell
Self Scrollable Text Inside Cascrolllayer
Uitableviewcell Separator Disappearing in iOS7
How to Get Distance of Object from iPhone Camera Using Image Exif Meta Data
Auto Layout to Dynamically Size Uilabel Width
Cocoapods: Unable to Find a Specification for [Privatespec] Depended Upon by [Privateclientspec]
How to Custom Modal View Controller Presenting Animation
Uilabel Text Not Being Updated
Avplayer Stalling on Large Video Files Using Resource Loader Delegate
Uitableview:Viewforheaderinsection: Not Called During Reloaddata:
Cannot Assign Value of Type '() -> Void' to Type '(() -> Void)!'
How to Run Timer Though the App Entered Background or Is Terminated
Is There a Public API for Card View UI That Can Be Seen Across iOS 10
Launch a Local Notification at a Specific Time in iOS
How to Build .Ipa for React Native
How to Use Cocoapods with Playground
How to Make Sure API Requests Come from Our Mobile (Ios/Android) App
Navigationview and Navigationlink on Button Click in Swiftui