Open sivaonline opened 8 years ago
It only works when I test using the App ID (465374093524857) in the example: http://coenraets.org/apps/openfb/index.html So it seems that it's a problem with the way we configure the Facebook app.
I'm getting nothing when trying to use the openFB.api call either. Did you solve this? What do I need to do to configure my Facebook app to allow this?
me too. when i use my app id, openFB only fetch the user_id and the name...
and now, i need to fetch email and birthday
Pls help us the developer of openFB... :(
Before you read this i assume that your app facebook can get the "Name" and "ID" property
Hello all, i have tried every way and, i get the solution...
the solution is make the link graph api hardcoded (I'm not make a variable) to get the value that you want..
look at the picture ! No 1. change the "v2.5" as th graph api version that you use no 2. change the fields value ("id,name,email,birthday") to fields that you need to get from the user
that's all
it is very simple. you don't need to change anything in the openfb.js file. what you need to do is to change the call method in the index.html file
<script>
openFB.init({ appId: 'your-app-id' });
function login() {
openFB.login(function (response) {
if (response.status === 'connected') {
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
openFB.api({
path: "/{your app version in facebook developer envi.}/me?",
params: { "access_token": accessToken, "?fields":"name,email,gender,user_birthday,locale,bio&access_token='"+accessToken+"'" },
success: function (response) {
var data = JSON.stringify(response);
// do whatever you want with the data for example
$(".data_div").html(data);
$(".data_email").html(data.email);
},
error: function(err){
alert(err);
}
});
}
else {
alert(“empty response returned”);
}
}
else {
alert(“not connected”);
}
},
{
scope: "public_profile,email,user_birthday"
});
}
</script>
very important! Please replace {your app version in facebook developer envi.} with your app version like v2.0 or v2.5
also don't forget to change 'your app id' to you facebook app id example 432046826485152
I tried above 2 solutions but getting error while retriving the email id i.e "an active access token must be used to query information about the current user javascript". Can anyone suggest a solution?
could you please write out a code sample on how you tried it? maybe we could help figuring out whats wrong with your code
Here is the code, `openFB.login(function (response) { if (response.status === 'connected') { if (response.authResponse) { var accessToken = response.authResponse.accessToken; openFB.api({ path: "/v2.5/me?", params: { "access_token": accessToken, "?fields":"first_name,last_name,email,&access_token='"+accessToken+"'" }, success: function (response) { var data = JSON.stringify(response);
},
error: function(err){
alert(JSON.stringify(err));
}
});
}
else {
alert('empty response returned');
}
}
else {
alert('not connected');
}
}, { scope: "public_profile,email" });`
I am able to get the first_name and last_name but not able to get email id.
try it by changing this
params: { "access_token": accessToken, "?fields": "first_name,last_name,email,&access_token='" + accessToken + "'" },
to this
params: { "access_token": accessToken, "?fields": "first_name,last_name,email&access_token='" + accessToken + "'" },
that is removing the coma after the fields parameter email.
Removed coma. Still facing same issue.
in your openfb.js does the function api(obj){...} looks like the below code ?
` function api(obj) {
var method = obj.method || 'GET',
params = obj.params || {},
xhr = new XMLHttpRequest(),
url;
params['access_token'] = tokenStore.fbAccessToken;
url = 'https://graph.facebook.com' + obj.path + '' + toQueryString(params);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
if (obj.success) obj.success(JSON.parse(xhr.responseText));
} else {
var error = xhr.responseText ? JSON.parse(xhr.responseText).error : {message: 'An error has occurred'};
if (obj.error) obj.error(error);
}
}
};
xhr.open(method, url, true);
xhr.send();
}`
Yes it is exactly same.
on my end the code is working perfectly .
this is what i used:
You are calling with v2.0. Where as my app version is 2.5. Let me try with 2.0.
okay. maybe that will help
Still not able to get the email id field even after changing the version. I am trying with this app id '940903142645622'. Is there any configuration need to make through app settings. In settings it shows persmission granted for email, public_profile and user_friends.
try to see if accessKey is treu by testing from you code this line:
success: function (response) { alert(accessToken); }
if you can see the alerted accessToken then the code should be okay. maybe the user email address is not being verified by facebook. I assumed so because you said you were able to get the firstname and lastname
This works for me.... In openfb.js
function api(obj) {
var method = obj.method || 'GET',
params = obj.params || {},
xhr = new XMLHttpRequest(),
url;
params['access_token'] = tokenStore['fbtoken'];
params['fields'] = 'id,name,email';
url = 'https://graph.facebook.com' + obj.path + '?' + toQueryString(params);
Nice . I am happy for you:)
MacGWik solution works for me. Thanks!
the same of chalingui, MacGWik solution works for me, and really thank you very much for the help , I was very useful
wew.. this just about the trust for the library, we just need to make sure if the library works properly, because in these case, i need to add some code and it bypassing the code inside the library. but it works!!! thanks!
How can I get the email address in an alert or in a textfield while using MacGWik methods? Please help.
just read my comment at the top @ibadrehman90
I've tried it and it works
*I make it hardcoded because I don't undestand how to make a variable for it, so If, your API version is different with the picture, please change it to yours.
In my case, I use API version 2.5 and I give permission on the facebook app to get the user email*
I found a sort of hybrid approach that worked for me:
1) hard-code version into openfb.js like in MacGWik's screenshot but DO NOT hardcode fields
url = 'https://graph.facebook.com/**v2.6**' + obj.path + '?' + toQueryString(params);
2) use the "params" field in openFB.api as in abiodunadigun's code, but remove the &access_token='"+accessToken+"'"}
part at the end and the ?
before fields
so that it just looks like:
params: { "access_token": accessToken, "fields":"name,email,gender,user_birthday,locale,bio" }
The @MacGWik's solution works for me.
This was the solution for me:
openFB.api({
path: '/v2.8/me',
params: { "access_token": accesstoken, "fields":"id,name,email" },
success: function(data) {
Mushaqdeen solution Works to me Thanks a lot :) :) :)
In openfb.js
function api(obj) {
var method = obj.method || 'GET',
params = obj.params || {},
xhr = new XMLHttpRequest(),
url;
params['access_token'] = tokenStore['fbtoken'];
params['fields'] = 'id,name,email';
url = 'https://graph.facebook.com' + obj.path + '?' + toQueryString(params);
@martinskou thank you! your solution bring my smile back!
After login though openFB, i didnt get the Emailid ,gender and first_name.
Please, Any suggestion guys