How to find user details by using his/her email ID or mobile number from Facebook? I want to get user details on my website using my app id access.
Please help me out this.
Try this. You need his facebook ID or his facebook name.
var fields = [
'id',
'name',
'first_name',
'middle_name',
'last_name',
'gender']
FB.api('/{insertIDhere}', {fields: fields}, function(details) {
// output the response
});
Or take this code from the FB Api Documentation
FB.api(
"/{user-id}",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
to login you need something like this :
FB.login(function(response) {
if (response.authResponse) {
//login successfull
} else {
//anything else
}
}, {scope: 'public_profile,email,user_friends'});
If you are logged in you could use something like this:
FB.api(
"/me?fields=id,name,picture.redirect(false).type(large)",
function (response) {
if (response && !response.error) {
facebookId = response.id;
facebookName = response.name;
facebookProfilePicture = response.picture.data.url;
callback(facebookUser);
}else{
}
}
);
You can't. Searching by email or phone is not possible.
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#search
Related
I can get the id and username from facebook connect, but I cannot retrieve the email !
Here is the JS script:
function connectionFacebook()
{ console.log('connectionFacebook called');
FB.api('/me?fields=email,name', { fields: 'name, email' }, function(response)
{
console.log(response);
response gives me:
Object {name: "John Doe ", id: "11112222333344445555"}
But no email !
PS. I guess it uses some old FB connect js since I work on an quite old site.
I have no idea what version of FB it uses, but I guess an old one !
ex: of code found in site;
FB.Event.subscribe('auth.login', function(response)
{
connectionFacebook();
;
});
FB.getLoginStatus(function(response)
{
if (response.authResponse)
{
connectionFacebook();
}
else
{
// no user session available, someone you dont know
//alert("getLoginStatus:deconnecté");
}
});
$.fn.connexionFacebook = function( ) {
return this.each(function () {
FB.init({
appId : xxxxxxxxx,
status : true,
cookie : true,
xfbml : true
});
});
}
})( jQuery );
<script src="http://connect.facebook.net/fr_FR/all.js"></script>
<fb:login-button show-faces="false" width="450" perms="email,user_birthday,user_location" size="medium">FaceBook connect</fb:login-button>
I'd guess that you don't have a permission to access the user's email. Facebook requires you to set the scope that determines which information you need to access.
In you case you need to specify the scope as public_profile,email to access the email. you can do that when your user logs in. Either with the API call:
FB.login(callback, { 'scope': 'public_profile,email' });
or with the button:
<fb:login-button scope="public_profile,email"></fb:login-button>
Specifying the email in the scope will ask the user to share her email address with your application when she logs in:
I get the following error when trying to access a user's invitable friends list through a Facebook Canvas App:
"error":{"message":"(#15) This method is only accessible to Games."
I have searched all over the web and the consensus to get past this error is that your app has to be :
classified as a 'Game' within your app's settings
have a Canvas presence - which means enabling the Canvas platform within your app's settings
So my Facebook app was already set as a Canvas app. I did this under 'Settings' and just added my Secure Canvas URL.
Next I had to classify my app as a 'game'. OK, less clear, but I changed the Category of my app to 'Game' under 'App Details' and I also set a 'Sub Category' for my game.
But the error persists. I am still getting: "error":{"message":"(#15) This method is only accessible to Games."
The call that generates this error is just the stock standard invitable friends javascript that I got from the Facebook website:
/* make the API call */
FB.api(
"/me/invitable_friends",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
Please help!
this works perfectly with yours conf like the tutorial:
$( document ).ready(function() {
FB.init({
appId: appId ,
frictionlessRequests: true,
status: true,
version: 'v2.4'
});
FB.AppEvents.activateApp();
FB.Event.subscribe('auth.authResponseChange', onAuthResponseChange);
FB.Event.subscribe('auth.statusChange', onStatusChange);
});
function onStatusChange(response) {
if( response.status != 'connected' ) {
login(loginCallback);
} else {
getMe(function(){
getPermissions(function(){
if(hasPermission('user_friends')) {
getFriends(function(){
getInvitablefriends();
});
} else {
console.log("without permissions")
}
});
});
}
}
function getInvitableFriends(callback) {
FB.api('/me/invitable_friends', {fields: 'id,name,first_name,picture.width(120).height(120)'}, function(response){
if( !response.error ) {
console.log(response.data);
callback();
} else {
console.error('/me/invitable_friends', response);
}
});
}
My function is :
function CallAfterLogin()
{
FB.login(function(response)
{
if (response.status === "connected")
{
LodingAnimate(); //Animate login
FB.api('/me', function(data)
{
console.log(data);
if(data.email == null)
{
alert("You must allow us to access your email id!");
ResetAnimate();
}
else
{
AjaxResponse();
}
});
}
});
}
Instead of writing on console I want show data in browser, how can it be done?
I tried with $("#mydiv").text(data); , $("#mydiv").html(data); which dont work.
me/movies gives error :
You must allow us to access your email id
You can add the scope like this-
FB.login(function(response)
{
}, {scope: 'user_interests, user_likes, etc..'});
I'm writing a facebook app in which the logged in user (a) chooses a friends from their friends list (b) and then the app posts on their friends wall (a posts to b).
I ask from the user the publish_stream permissions.
This is the code for showing the friends selector popup:
function selectFriends() {
FB.ui({
method: 'apprequests',
message: 'You should learn more about this awesome game.', data: 'tracking information for the user'
},function(response) {
if (response && response.request_ids) {
//alert(typeof(response.request_ids));
//alert(response.request_ids);
alert (response.request_ids);
len=response.request_ids.length;
alert(len);
if (len>2) {
alert("Select no more than one friend");
}
else {
user_req_id = response.request_ids[0];
postOnFirendsWall(user_req_id);
}
}
else {
alert('Post was not published.');
}
});
}
This is the postOnFirendsWall(user_req_id) method:
function postOnFirendsWall(friend_id)
{
/** Auto Publish **/
var params = {};
params['message'] = 'message';
params['name'] = 'name';
params['description'] = '';
params['link'] = 'https://www.link.com/';
params['picture'] = 'http://profile.ak.fbcdn.net/hprofile-ak-snc4/203550_189420071078986_7788205_q.jpg';
params['caption'] = 'caption';
var stam = '/'+friend_id+'/feed';
FB.api('/'+friend_id+'/feed', 'post', params, function(response) {
if (!response || response.error) {
alert('Error occured');
alert(response.error);
} else {
alert('Published to stream - you might want to delete it now!');
}
});
return false;
}
But I keep getting the following error: (#210) User not visible.
Can you see why?
Have you verified that user A has permission to write on the wall of user B? If not, this will never work.
Also, why are you using an apprequests dialog if you want to post on a friend's wall?
My app does the following:
1. Asks for the friends_online_presence permission.
2. If the user gave the permission (i.e the callback indicated success) I immidiately test for the permissions(*) and depending on the result pull the users' details (a call to getOnlineFriends).
The problem is that it takes a couple of miliseconds for facebook to update the permissions on their servers. So when I immidiately query for the permissions I just asked for facebook always says that I don't have the permission.
Using setTimout "solves" the problem.
How can this be solved deteministically?
I've tried some primitive form of polling but it got the browser stuck (and it also seems like a crooked solution).
(*) 'SELECT friends_online_presence FROM permissions WHERE uid=me()'
The code:
c2p.facebook = {
requestViewOnlineFriendsPerms: function (callback) {
myStuff.requestPermission('friends_online_presence', callback);
},
requestPermission: function (perms, callback) {
FB.ui({
method: 'permissions.request',
perms: perms,
display: 'popup'
}, function (response) {
if (response && response.perms) {
if (callback) {
callback(true);
}
} else if (!response.perms) {
if (callback) {
callback(false);
}
}
});
fql: function (q, callback) {
FB.api({ "method": "fql.query", "query": q }, callback);
},
getOnlineFriends: function (callback) {
var q = 'SELECT friends_online_presence FROM permissions WHERE uid=me()';
c2p.facebook.fql(q, function (rows) {
var isPermissionGranted = true;
var q2 = "SELECT uid, name, pic_square, online_presence FROM user WHERE online_presence IN ('active', 'idle') AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY name";
if (rows[0].friends_online_presence == 0) {
isPermissionGranted = false;
q2 = "SELECT uid, name, pic_square FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY name";
}
c2p.facebook.fql(q2, function (arr) {
callback(arr, isPermissionGranted);
});
});
}
}
// The way I call this code is:
c2p.facebook.getOnlineFriends(function (arr, isPermissionGranted) {
$("#tmplFriends").tmpl(arr, { getIndex: function () { return $.inArray(this.data, arr); } }).appendTo("#friendsDiv");
if (!isPermissionGranted) {
$('.c2p_hidden').show();
}
});
How c2p.facebook.fql(q2, function (arr) {...} could see the callback variable? it's crazy.
The callback is a local variable of the getOnlineFriends function.
Tom just place your FQL query inside the
if (response && response.perms) {
}
for example suppose I want to fetch user details thru fql what I do is:
function onloginCall(){
FB.login(handleSessionResponse,{perms:'email,read_stream,publish_stream,offline_access'});
}
function handleSessionResponse(response){
// if we dont have a session, just hide the user info
if (!response.session) {
return;
}
else{
FB.api({
method: 'fql.query',
query: 'SELECT name, pic_square , email FROM user WHERE uid=' + FB.getSession().uid
},
function(response) {
var user = response[0];
store_fbuser_data(FB.getSession().uid,user.name,user.pic_square,user.email) ;
}
);
}
}
I guess this will solve your problem of delay. As this query will only execute when you have sufficient permissions.