Facebook javascript sdk return wrong user id - facebook

I am trying to get user information..and I'm using this method
FB.api('/me', function(response) {
console.log(response);
});
but the problem is that the response contains a wrong user_id.

Probably you're using Login 2.0 respectively the new JS SDK (https://developers.facebook.com/docs/javascript/quickstart/v2.0) and are getting an app-invidual user_id as described in the Graph API v2.0 Upgrading Guide:
https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids

Related

Unable to fetch user using Facebook js sdk v2.10 on Firefox

I am trying to add facebook authentication on our website using Facebook Javascript SDK v2.10. My aim is to login via Facebook and then fetch the user which was authenticated.
The problem I am facing is that on Firefox, I am unable to fetch the authenticated user.
I have created a test page HERE
When you click on the button 'Login via Facebook', the FB.login function is called. When the response is received, I am calling the FB.api function. Following is my code
FB.login(function(response) {
let p1 = document.createElement('p');
p1.innerHTML = "FB.login response follows:<br>"+ JSON.stringify(response);
document.body.appendChild(p1)
FB.api('/me', {fields: 'id,first_name'},
function(response) {
let p2 = document.createElement('p');
p2.innerHTML = "FB.api response follows:<br>"+ JSON.stringify(response);
document.body.appendChild(p2)
});
});
In Chrome,the callback of FB.api is called and the response is received,but, in Firefox, this is not happening. Kindly help me figure out why this is happening
Ok. I was using Facebook sdk in Polymer app. The sdk documentation suggests adding the sdk initialization code in index.html.
But, for Polymer, you need to add the code in the connectedCallback method of your root app (my-app.html if you are using polymer-starter-kit)
For reasons unknown, the webcomponent-loader.js blocks Facebook initialization on Firefox, if sdk code is added in index.html.

how to integrate facebook js login and laravel socialite?

i'm facebook js sdk for users login,
at the server side i want to get the user data
i'm trying to use
Socialite::with('facebook')->user()
to make it work it need 2 query string code and status
in my JavaScript i'm using the following
var auth_status_change = function(response) {
console.log(response);
if(response.status == "connected")
{
window.location = "{{URL::to(App::getLocale()."/fb_login")}}?code="+??+"&state="+???;
}
}
FB.Event.subscribe('auth.statusChange', auth_status_change);
how to get the state and code values to create a valid callback URL for socialite
You're trying to combine 2 things that do the same thing, but one on the server side and one on the client side, that won't work.
Laravel Socialite uses your app token to redirect your user to Facebook, authorize your app to use Facebook on their behalf (token) and provides you with user data. With the token you can do API calls from Laravel.
The Facebook JS SDK does the same thing, but in the browser. It fetches a token which it uses to do API calls.
Check out https://laracasts.com/series/whats-new-in-laravel-5/episodes/9 on how Socialite works.
Unless you are using the JS SDK functionality, you can leave it out and just add a link to a socialite route which redirects it to Facebook. That call will provide you with the code and state required to fetch the user.

Send Friend request to a facebook user using Facebook Graph API 2.x

I want to send friend request from my app to any facebook user (who is not my friend but I have his app-scoped-facebook id.)
(Just kind of adding 'Add Friend' button in my app)
Is there any way to implement this in facebook API 2.0 and above
Adding friends is not possible through the API
You can call http://www.facebook.com/addfriend.php?id=[USER UID]
Where [USER UID] is a valid facebook user id.
I got one solution but don't know it will be deprecated or not as it is of v1.0
But at present its working :)
FB.ui(
{
method: 'friends',
id: fbid
},
function(data){
console.log(data);
}
);

Use Facebook Graph Api to get info about comment?

I want to get info (text and uid) from comments in my application.
https://graph.facebook.com/commentID
I think I need my apps access token to get the comment info. How do I get it and echo/alert with comment's info?
you need to request the user to allow your application and then use the access token you get in the request to the Graph API...
the allow of the application can be done in both server side or Javascript (I prefer JS)
an example for how to allow an application and invoke a graph api call can be found in the facebook developers js sdk documentation below:
http://developers.facebook.com/docs/reference/javascript/FB.login/
function loginAndGetData(){
FB.getLoginStatus(function(response){
if(response.status=="connected"){
FB.Api("commentID",onGotData);
} else {
FB.Login(function(response){
if(response.status=="connected"){
FB.Api("commentID",onGotData);
}
});
}
});
}
function onGotData(data){
console.log(data)
}

Reusing Access_Token from server in Facebook JS SDK

I am using Facebook c# SDK to authenticate user (successfully). But I want also to use FB.ui JS methods on client. Is there any way to "reuse" already received access_token from c# SDK in Facebook JS SDK? I don't want to call FB.Login because I've already authenticated user on server side.
Just put the access_token string to a hidden field and get the value through javascript and pass it to the JS API Methods.
FB.getLoginStatus(function(response) {
if (response.authResponse) {
fbUserId = response.authResponse.userID;
token = response.authResponse.accessToken;
} else {
fbUserId = 0;
}
});
you will get access token