Facebook Matching API - Page Scoped ID (PSID) empty for other users - facebook

I have a bunch of users registred on my website thanks to Laravel Socialite and Facebook Login. When a user creates a account their app_scoped_id is save under provider_user_id.
I need to get the page_scoped_id of a user on my page instead of app_scoped_id.
To do so I am using the Facebook Matching ID whose documentation could be find here
The code
$fb = new Facebook(...);
$response = $fb->get($user->socialAccount->provider_user_id . '/ids_for_pages?fields=id&page=' . env('FB_PAGE_ID'), env('FACEBOOK_PAGE_TOKEN'));
$pageScopedId = $response->getDecodedBody()['data'][0]['id'];
Issue
It works perfectly for myself, but when I'm trying to get other users' page scoped id, it returns an empty array.

The Facebook Matching API is able to match page scoped id and app-scoped id if and only if they both exist.
In my case, page scoped id has not been associated with users (since they have not interacted with the messenger yet).

Related

Facebook Api search users by name returning empty data

I used this url with access token https://graph.facebook.com/search?q=Marcus&type=user&access_token= and it returns empty data data []
Settings https://i.imgur.com/6hEiO5y.png
I was trying to get a list of users with their name using javascript. Is it possible ?
as mentioned in the comments here is the official Facebook note, that you cannot search for type = user anymore:
https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#search-4-4
The /search endpoint for pages, videos, groups and events has been disabled by facebook after the cambridge analytica scandal.
Faceboook Changelog:
You can no longer use the /search endpoint with the following object types:
event
group
page
user

Facebook: Can't publish on user feed in test mode

I have developed a Facebook app in test mod and I want to publish on the test user's wall.
this is the link where the user register and accept the permissions:
https://www.facebook.com/dialog/oauth?type=user_agent&client_id=MY_APP_ID&display=popup&redirect_uri=THE_URL&scope=email%2Cpublish_actions
After that I am getting an some sort of a token, using this token I am doing the following request to the graph:
/oauth/access_token?client_id=MY_APP_ID&client_secret=MY_APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=".$token
the token coming back is now being used by me to get the user's details from the graph:
/me/?$user_access_token&fields=name,age_range,id,email,gender,currency,locale,timezone"
I am getting in result all the fields listed above. (one strange thing, the id coming back is not the test user's public id, the other field are correct...)
when I want to post so someones wall I am running this int the graph:
/oauth/access_token?client_id=MY_APP_ID&client_secret=MY_SECRET&grant_type=client_credentials
the token coming back will be used here:
$token = self::getAccessToken($app_id,$app_secret);
$post_array = array();
$post_array['access_token'] = $token;
$post_array['message'] = urlencode($message);
$post_array['link'] = urlencode($link);
$res = self::post("https://graph.facebook.com/".$user_id."/feed?",$post_array);// the user id might be wrong?
and I am getting the following error:
{"error":{"message":"(#200) Permissions error","type":"OAuthException","code":200,"fbtrace_id":"EO5WvMfYYgC"}}
What can it be?
the fact that I am in test mod?
or maybe the user's ID i got back is wrong?
Thanks
The ID is correct, you only get an "App Scoped ID". You are not supposed to use the global/public ID anymore, and you should use /me/feed for posting, not /user-id/feed. You can only post on the wall of the authorized user anyway.

Ionic with Backand social login: profile picture

I'm developing an application with ionic and Backand and I'm using the sign in with social accounts with the Backand service.
The social login process is OK, but I want to get the ID from Facebook and Google plus in order to get the profile picture.
I was talking with the support of Backand and I know that in Security and Auth there is an action "beforesocialSignUp" and I have not commented the line to get the data:
'use strict';
function backandCallback(userInput, dbRow, parameters, userProfile) {
// get facebook id and put in fuid field that you need to add to your user object
userInput.fuid = parameters.socialProfile.additionalValues.id;
// get gender from facebook and put in gender field that you need to add to your user object
// userInput.gender = parameters.socialProfile.additionalValues.gender;
}
And I have created the fuid field in my user object, but, when I make a login with Facebook or Google+ It doesn't save nothing. The login is OK but I can't get the ID data.
Any idea?
I had exactly the same problem.
The solution was to set the where condition of the BeforeSocialSignUp function from false to true.
This is nowhere in the documentation explained.
It took me 3 day ro figure this out :-(
Now the login works as expected and the fuid field gets assigned.
My next step is to get the profile picture from the FB Account, but therefore I have to make an API request to facebook with a user access token which I dont know how to get from backand.

Get posts from page that hasn't setup a custom alias?

I'm visiting a number of Facebook pages and collecting information about their posts. When the Facebook page has created a custom username / alias, I can simply query their page like so, using their ID:
$accessToken = FACEBOOK_APP_ID.'|'.FACEBOOK_APP_SECRET;
$url = 'https://graph.facebook.com/104958162837/?access_token=' . $accessToken;
However, if they didn't bother to setup a custom username / alias, then it won't work, even if I specify:
The default alias that FB gave them when they created the page (looks something like My-Page-Name-104958162837).
The numerical ID of their page.
What gives?
Works fine for me that way, if use a User Token:
/129319107123637
/129319107123637/feed
Just try it in the API Explorer, after authorization: https://developers.facebook.com/tools/explorer/145634995501895?method=GET&path=129319107123637&version=v2.5
It only does not work with an App Token if the Page is restricted by age or location. In that case, you have to use a User Token of a User who is allowed to see the Page, of course.

Facebook Graph API - Access token for page likes, name and url

I'm trying to update some old PHP code which is supposed to get the name, likes and a link to the given Facebook page. This is the current old code:
$fbsite1 = json_decode(file_get_contents('http://graph.facebook.com/page1'));
$fbsite2 = json_decode(file_get_contents('http://graph.facebook.com/page2'));
$fbsite3 = json_decode(file_get_contents('https://graph.facebook.com/page3'));
for($j=1; $j<=3; $j++){
$data[] = array(
'name' => ${'fbsite'.$j}->name,
'likes' => ${'fbsite'.$j}->likes,
'link' => ${'fbsite'.$j}->link
);
}
The problem is that this method requires an access token, which I'm not quite sure how to get. I've looked at the Facebook API reference, but there seems to be a few different access tokens (different permission etc.). Which one do I need to accomplish this? How do I get it?
If the pages are public, then you only need an app access token.
So create an app in the FB dev section (if you have not done so already), and then include your app access token in those request URLs:
http://graph.facebook.com/page1?access_token=…
FYI, you should consider requesting all that data in one go, instead of making multiple API requests. You can do that using this syntax (for up to 50 ids in one request),
http://graph.facebook.com/?ids=page1,page2,page3&access_token=…
And you will have to explicitly ask for the name, link and likes fields now (otherwise you will get name and id only):
http://graph.facebook.com/?ids=page1,page2,page3&fields=name,likes,link&access_token=…