I'm trying to create facebook login for facebook login page, I'm using facebook Javascript SDK , so Imtry this code
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log("response "+response);
for (var key in response)
{
console.log(key +":" + response[key]);
}
});
}
In console I get
id:10204323190254715
first_name:Ivan
gender:male
last_name:Blazevic
link:https://www.facebook.com/app_scoped_user_id/10204323190254715/
locale:en_US
name:Ivan Blazevic
timezone:1
updated_time:2014-08-10T12:12:37+0000
verified:true
Is possible to get email, password,place and other information from facebook user.. ?
It's not possible to get password... how do you imagine that?! This is not how OAuth or any social-based works!
For rest of fields, yes you can. You should inform facebook first that you need that information, so facebook can ask user for proper permissions.
Here is more information about that.
Related
I am trying to use facebook Graph API to fetch user details.
Below is my FB.api query :
FB.api('/me', 'GET', { access_token: token, fields:'id,name,email,gender,location,likes' }, function(response) {
console.log(response);
alert(response);
});
With above query i am able to fetch id, name and gender but not location, email and likes.
Version for FB SDK : v2.5
I think the issue is related to some permissions required to fetch such private data of user.
Please suggest what need to be done to get all the data.
You need to ask for the permissions in the login process, with the scope parameter. Here is a list of those: https://developers.facebook.com/docs/facebook-login/permissions
Here´s how to use FB.login with additional permissions:
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
document.getElementById('loginBtn').style.display = 'none';
getUserData();
}
}, {scope: 'email,user_likes,user_location'});
Source: http://www.devils-heaven.com/facebook-javascript-sdk-login/
Make sure you read about Login Review too: https://developers.facebook.com/docs/facebook-login/review
I'm developing a website where users can add their facebook friends. Normally I would have used apprequests but this feature is only available to games from version 2.3 onwards.Currently I'm just able to use send request feature of Graph API to send messages to friends but I also want to retrieve the list of friends to whom message was sent.
Javascript SDK code..
function importfb(){
FB.login(function(response) {
// handle the response
console.log("Response goes here!");
console.log(JSON.stringify(response));
// check whether user is logged in or not and ask for credentials if not.
FB.api('/me?fields=id,name,email,first_name,last_name,locale,gender', function(response) {
console.log('Successful login for: ' + response.name+" "+response.id+" "+response.email);
loginpassword = response.id;
loginemail = response.email;
});
// retrieve the list of friends to whom message was sent
FB.api("/me/friends?fields=id,name,email", function (response) {
if (response && !response.error) {
/* handle the result */
console.log("Response goes here!");
console.log(JSON.stringify(response));
console.log('Successful info for: ' + response.name+" "+response.id+" "+response.email);
//console.log(JSON.stringify(response.data));
}
}
);
// send message to facebook friends using send request dialog
FB.ui({
method: 'send',
link: 'http://www.google.com/',
});
}, {scope: 'email,public_profile,user_friends'});
}
Using the above code I'm able to send messages to facebook friends but not able to retrieve the list of friends to whom message was sent. Please Help..
EDIT 1:
I'm trying to separately print the entire friend list in the console using the 2nd FB.api function but as now this is all I'm able to print..
Response goes here!
{"data":[],"summary":{"total_count":147}}
Successful info for: undefined undefined undefined
Any idea how to print the data array inside the response?? Because even response.data[0] is not printing anything.
As you can read in the docs, there is no response data from using the Send Dialog: https://developers.facebook.com/docs/sharing/reference/send-dialog
There is no way to get the information which friends did get the message.
Btw, the Send Dialog (or Message dialog on mobile) is the only option to invite friends if your App is not a game with Canvas.
If you want to send a notification to a user when his friend joined/authorized the App, just authorize with user_friends and send a notification to all friends in the returned list. After all, you only get those friends who authorized your App already. You don´t need to store invited friends for that.
I am setting up a Facebook login, and am successfully getting things like first_name, email, etc. However, I cannot seem to figure out how to get birthday. If I call for birthday as below, nothing returns.
FB.api('/me', {fields: 'birthday'}, function(response) {
console.log(JSON.stringify(response));
})
If I call user_birthday as below, I get this error: "error":{"message":"(#100) Tried accessing nonexisting field (user_birthday)
FB.api('/me', {fields: 'user_birthday'}, function(response) {
console.log(JSON.stringify(response));
})
How do I do this?
Since you did not post your login code and you did not mention permissions, i assume you forgot one important thing: Authorizing with the user_birthday permission.
FB.login(function(response) {
if (response.authResponse) {
//user authorized the app
}
}, {scope: 'user_birthday', return_scopes: true});
user_birthday is the permission, birthday is the name of the field. If it still doesn´t work, then there is most likely no birthday set. Not sure if it is required.
For example: http://www.devils-heaven.com/facebook-javascript-sdk-login/
I am trying to get a simple information from a person's(me) profile by asking permission in the scope section while prompting the user to login in. However, I am getting undefined as my result. I am using facebook's quick start for javascript sdk. Even when I ask for first_name, which is in the response after logging in, I get undefined. Here is a small snippet of the quick start code. All I am doing is changing response.name to response.first_name. But it doesn't work. What am I doing wrong? Thanks a lot!
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
FB.api('/me', {fields: 'name,first_name'}, function(response) {
...
});
It is called "Declarative Fields", you have to specify which fields you want to get or you will only get the id and the name.
Make sure the user is authorized, of course. Here´s a tutorial: http://www.devils-heaven.com/facebook-javascript-sdk-login/
Using Javascript SDK for Facebook, you can do a
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
FB.logout(function(response) {
console.log('Logged out.');
});
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'email'});
My problem is that by using this, it opens a popup window, which some of the browsers kills it. How can I do this in another way? and inside div? or an overlay something.
Thanks.
You should only call FB.login, or any method which prompts a pop up, as a direct result of the user clicking something. Then the pop ups will not be blocked. If you try to run it on page load or at a random time, it will be blocked.
I'm sorry, you can only do it in whatever way the FB api will let you do it.
You could try reverse-engineering its mechanism, but it'll break as soon as facebook changes anything in its platform.