Facebook Webhooks To Find Who Likes Your Page - facebook

I have a webhook setup to watch the 'feed' field on a FB page I am an admin of. I am trying to keep track of WHO likes our PAGE, not posts on the page.
So far it seems to be very erratic about the hooks it sends for Page Likes. I have only seen one of them fire, and it does not seem to include the user info, only that somebody liked the page. Example response below.
+"entry": array:1 [▼
0 => {#1535 ▼
+"changes": array:1 [▼
0 => {#1533 ▼
+"field": "feed"
+"value": {#1534 ▼
+"item": "like"
+"verb": "add"
}
}
]
+"id": "15093830XXXXXXXX"
+"time": 1561391263
}
]
+"object": "page"
}
Is there anyway to automatically find who likes your page? Even another endpoint I can call once this trigger fires, to get the list of people and do a diff?
Thanks for your help.

Related

Facebook Graph Api | page follower count

I want to take the number of followers and likes of an public page. I try this request
https://graph.facebook.com/v2.9/138432502881936?fields=engagement,fan_count&access_token=access_token
Then return result:{
"engagement": {
"count": 9894383,
"social_sentence": "9.8M people like this."
},
"fan_count": 9894383,
"id": "138432502881936"
}
Page's likes count changes instantly but I can not get followers. Is there a way to do this ?
I found a solution by using a HTTP request, not using the API. I just request the page www.facebook.com/whatever_name_of_the_page, no need to be logged in, and then check for a match of 'XXX people follow this' using regular expressions. I tested with python requests package and worked just fine.

Facebook Graph API: Webhook for LIKE and UNLIKE plus receiving the user

I have subscribed to the "feed" event with a webhook. So far I receive the following object when someone clicks on the "like" button of my page:
{"entry": [
{"changes": [
{
"field":"feed",
"value":{
"item":"like",
"verb":"add",
"user_id":11111111111111
}
}],
"id":"2222222222222",
"time":33333333
}],
"object":"page"}
Question 1: I wounder, is it possible to also get an event when the user "unlikes" the page?
Question 2: With this user_id, how can I get the user object from facebook? Is this the "real" facebook user id (i could not get an user object through the graph explorer so far) or is a page specific id of the user?
Thanks in advance!
EDIT: For Question 2, I just needed to add the page access_token to the request to get the user object.

FB Api: Tag/mention another page on my own fan page

I have a fan page which I am an admin of. I'd like to create a simple button - when I click it, it would create a post on my Fanpage, with a predefined a message and a photo. I have been able to achieve this fairly simple using the Graph API:
$args = array(
'access_token' => <my_acc_token>,
'url' => <url_of_image>,
'message' => <my_message>
);
try{
$facebook->api('/<id_of_my_page>/photos', 'POST', $args);
}catch(Exception $o ){
print_r($o);
}
ISSUE:
I would like to now be able to also Tag or Mention another page in that post, but nothing seems to work!
I tried adding a #[user-id-of-page] into the message property or my $args array - but to no avail.
Is tagging/mentioning even possible without having to use Facebook actions? How can this be achieved?
https://developers.facebook.com/docs/opengraph/using-actions#pages
Be aware that you have to go through the review process with this, else you can only mention your own Pages.
So in order to mention other Pages, you would need to get the permissions manage_pages and publish_actions approved, and you need to get the "Page Mentions" feature approved. Go to "Status & Review" in your App settings and click on "Start a Submission". Scroll down in the list on the left and you will find "Page Mentions".

How to check if someone is liked my fanpage from my website?

I want to check if a user liked my fan-page from my website and if he did i skip the step and if he didnt i want to suggest him to like my fan-page,its all on my website i dont want to put a landing page or something else on my fan-page.all of it is on my website,i don't want to put a landing page or anything else on my fan-page.
Thanks
there are only 2 ways for this:
-) use the edge.create event: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
downside: this can only check right after clicking a like button on your website. so, if the user comes back, you can´t be sure if the like button is still clicked. also, you never get the id of the user, of course
(deprecated)
-) authorization with facebook login > you can check for the user likes > user_likes permission needed. but i doubt that you really want to authorize the user just for this...
the graph api call you could use:
me/likes?target_id=[page-id]
subscription:
permission user_subscriptions needed. graph api call would be the following:
me/subscribedto?user=[user-id]
You need user_likes permission to view like information about the current session user.
refer to: http://developers.facebook.com/docs/reference/login/user-friend-permissions/
then simply use fql to request information.
SELECT page_id FROM page_fan WHERE uid=me() AND page_id=22934684677
If user likes the page graph will return id of page.
Example graph request like for page Facebook.
http://developers.facebook.com/tools/explorer/135669679827333/?fql=SELECT%20page_id%20FROM%20page_fan%20WHERE%20uid%3Dme()%20AND%20page_id%3D20531316728
{
"data": [
{
"page_id": 20531316728
}
]
}
Else array will be empty.
{
"data": [
]
}

facebook: how to show content in page only if user likes it

how can i show or display information only if the user is fan or likes my page? there are several pages that do that to catch more fans. thanks!
edit:
like the victorias secret page with this box
http://www.facebook.com/victoriassecret?v=app_117241824971601&ref=ts
My answer applies if you use an iFrame for your tab/canvas. First, you need to ask for permissions (just need basic info from user). Then, make a call to the Javascript API, like so:
FB.api('me/likes', function(response) {
});
This gives a JSON object of everything the user has liked. So, you have to loop through the response and try to find your page. If you are successful in finding it, display the awesome content!
Hope this helps!
Edit: Looking back, my answer was way off. This information is actually contained in the signed_request given by Facebook.
If you mean Facebook Page, use functions from Facebook API: Signed Request
$signed = parse_signed_request($_REQUEST['signed_request'], YOUR_APP_SECRET_KEY);
$signed = Array (
[algorithm] => HMAC-SHA256
[expires] => 13..
[issued_at] => 13..
[oauth_token] => ...
[page] => Array (
[id] => 29...
[liked] => 1
[admin] =>
)
[user] => Array ( [country] => cz [locale] => en_US [age] => Array ( [min] => 21 ) )
[user_id] => ..
)
If current user like your Facebook tab page, you find out from $signed['page']['liked']
If you're using the php sdk, you can use a call to the facebook object api and then determine if they have the like you want them to have.
$path = 'me/likes';
$likes = $facebook->api($path);
More info here
This is a privacy and security setting. Facebook Privacy FAQ
Page Tabs gets Signed Request that contain "liked" field
http://developers.facebook.com/docs/authentication/signed_request/
FQL isFan
http://developers.facebook.com/docs/reference/fql/page_fan/
Old REST API isFan
http://developers.facebook.com/docs/reference/rest/pages.isFan/
Legacy FBML isFan
http://developers.facebook.com/docs/reference/fbml/visible-to-connection/
There doesn't have to be any code involved. Just create a landing page (you could create a jpeg photo and link to the photo) and set that as the default landing page in your page settings. For users who are fans they go directly to the wall posts. All other people (non-fans) go to your specified landing page.
By the way, you realize that people can still access your content by just clicking on one of the tabs, correct? Even the Victoria Secrets example allows you to click on the "wall" tab, for example, and see the content.
A lot of people just like the page because it's the default landing page and they "think" they have to like the page first. It's more social psychology than anything else.
Google for Facewall Script, that should do what you want. But keep in mind to offer an option for users that not have Facebook Account.