I am trying to get updates when the like count of a page my app is on is updated. I am trying to accomplish this by using the FB Real-time Updates API
When I do a POST, with the object = "page" and the fields = "likes", I get a 400 error with the message '"likes" is an invalid field name'.
object = "page" and the fields = "name" works fine.
The documentation states you are allowed to subscribe to any public attribute.
For those playing the home game, here are the steps to reproduce the problem:
Get an OAuth token for your app:
https://graph.facebook.com/oauth/access_token?client_id=<app_id>&client_secret=<secret>&grant_type=client_credentials
Post to subscription URL:
https://graph.facebook.com/<app_id>/subscriptions
POST Variables:
'access_token' => `<access token from step 1>`,
'object' => 'page',
'fields' => 'likes',
'callback_url' => `<a callback url>`,
'verify_token' => 'testingstring123'
This isn't supported - from the section 'Real-time Updates' on https://developers.facebook.com/docs/reference/api/page/ :
The Page object supports Real-time Updates for picture, tagged and
checkins connections.
Note: Real-time updates are not yet supported for the total number of
Page checkins.
Subscribing to likes is only for pages that a user likes. The 'likes' object is what pages a user or page likes, not the count of how many people like your page, which cannot be subscribed to.
Related
We have a Facebook Shop and a Business Page, and are using Facebook Graph API to create Photo posts on the Business Page using the Javascript SDK running in a browser. How do you include the tagged Product in the Create Photo request?
https://developers.facebook.com/docs/graph-api/reference/photo/ mentions a tags field you can pass which is described as "Tags on this photo", however it has a tag_uid "The user_id of the tagged person". Is this tags field how you are supposed to tag a product?
A similar question from 2017 was not answered and is so old I thought I'd post a new one: Publish new facebook post with tagged product
What we've tried so far
To get a list of our products, we can use GET ${businessId}/owned_product_catalogs to retrieve a list of catalogs, and then GET ${productCatId/products with a filter: '{"custom_label_0":{"eq":"something_to_match"}}' to get a specific product in the catalog. So now we have the ID of a product we want to tag e.g. "4378279312278116". (we happen to use custom_label_x fields meaningfully, of course the filter could have been something else but this works for us)
To create the photo post, we can POST /${account.id}/photos with a payload like:
{ caption: 'Test caption',
url: image_url,
access_token: account.access_token,
tags: [
{
tag_uid: "4378279312278116",
tag_text: 'Test tag',
x: 10, y: 10
}
]
}
This request completes OK and does post the photo, but nothing is tagged on it when we view it on our page.
Trying to read the photo with GET ${photo_id} only returns basic infomation fields created_time, id, name. I can't see how to read further fields on the photo object to check if the tags data was associated with it correctly.
Any advice please?
I know how to make a post to a Facebook page via the API using PHP SDK, that is done like this:
$facebook->api('/xxxxxxxxxxx/feed', 'post', array('message'=> 'Hello world!', 'cb' => ''));
Where xxxxxxxxxxx is page id ;)
But doing that, I post to that page as me, Jamie, and not as the Page itself (admin).
So how do I post as Admin/Page instead of myself?
Thanks you for your time!
ANSWER (for lazy people):
First of all you need to make sure you have access to manage pages for user, ex:
<fb:login-button autologoutlink="true" perms="manage_pages"></fb:login-button>
Now you also gets a special token for every page user have access to once you get them.
PHP SDK Example:
//Get pages user id admin for
$fb_accounts = $facebook->api('/me/accounts');
//$fb_accounts is now an array
//holding all data on the pages user is admin for,
//we are interested in access_token
//We save the token for one of the pages into a variable
$access_token = $fb_accounts['data'][0]['access_token'];
//We can now update a Page as Admin
$facebook->api('/PAGE_ID/feed', 'post', array('message'=> 'Hello!', 'access_token' => $access_token, 'cb' => ''));
Check out this note regarding your question: http://developers.facebook.com/docs/api > Authorization > Page impersonation.
Long story short, you need the manage_pages extended permission.
And btw, have you checked this first ?
In PHP with facebook SDK, when I post from my app using /me/feed, if I use 'SELF' for privacy setting, it works fine. When I change it to CUSTOM with a list of ids to restrict to, I get an error for "friends" was not recognized. What does this mean?
// Works
$privacy = array(
'value' => 'SELF',
);
// Doesn't work and says 'Friends was not recognized'
$privacy = array(
'value' => 'CUSTOM',
'allow' => '{<id1>}'
}
I read through many questions on this topic before asking this one.
Also, this documentation from FB is confusing me as to what is and is not possible for an post from an app.
"Note: The privacy parameter only applies for posts to the user's own timeline and is ultimately governed by the privacy ceiling a user has configured for an app. It does not apply to posts made by an app on behalf of a user to another user's timelines or to Pages, events, or groups. In those cases, such posts are viewable by anyone who can see the timeline or content in the group or event."
you need to add a parameter called 'friends' with the value of 'SOME_FRIENDS'.
like this:
$privacy = array(
'value' => 'CUSTOM',
'friends' => 'SOME_FRIENDS',
'allow' => 'id1,id2,id3'
);
I am creating a simple CMS system whereby users can contribute inspirational posts made by brand pages on Facebook. All the user has to do is paste in a permalink to a post and the CMS will handle pinging the Graph API in order to acquire all the info it needs. (e.g. https://www.facebook.com/photo.php?fbid=10152047553868306&set=a.99394368305.88399.40796308305&type=1&relevant_count=1)
One of the requirements of the CMS is that like, comment, and share counts are included for each post. This is where I struggle.
Simply pinging the graph endpoint with a photo ID will only return a paginated list of likes/comments. There is no parameter for total likes or total comments. Fortunately, the photo table includes like_info and comment_info members for me to query upon. This works great for getting totals on photos:
SELECT like_info, comment_info FROM photo WHERE object_id = 10152047553868306
One would expect then that I could apply the same FQL SELECT on the status or video tables in order to get the like and comment info for status updates and video posts but you cannot. like_info and comment_info only reside on the photo table.
At least right now I can get like/comment total for photos, but I still see no indication on how to get share totals for a photo.
Is there a way I can reliably acquire like, comment, and share counts for video posts, photo posts, and status posts? Using any combination of Graph or FQL API?
Any help would be extremely appreciated.
I have found something like this for facebook graph api v2.8
$accessToken ="XXXXXXXXXX";
$fb = new Facebook\Facebook(array(
'app_id' => 'Facbook App Id',
'app_secret' => 'Facebook Secret Key',
'default_graph_version' => 'v2.8',
));
$params = array();
$request = $fb->request('GET', '/{post_id}/?fields=likes.limit(0).summary(true),comments.limit(0).summary(true)',$params,$accessToken);
$response = $fb->getClient()->sendRequest($request);
$graphNode = $response->getGraphNode();
$likeArr = $graphNode['likes']->getMetaData();
$commentArr = $graphNode['comments']->getMetaData();
echo "Total Post Likes : ".$likeArr['summary']['total_count'];
echo "Total Post Comments : ".$commentArr['summary']['total_count'];
use this:
SELECT user_id FROM like WHERE object_id=10151751324059927 LIMIT 1000
Hey all,
I've made a facebook application for a contest, which allows users to upload their photo. Once uploaded, the photo gets posted to a dedicated album on their profile. Once the photo is there, the users should collect as many likes as possible.
Currently i have tried both the Facebook Graph API and Facebook FQL to retrieve the amount of likes, but the retrieved likes don't always match the likes on a users profile.
Some users claim to have more then 200 likes, yet the API only returned a maximum of 101 likes so far.
All users are requested to grant the application the following permissions:
user_hometown, publish_stream, read_stream, user_photos and offline_access
Using Facebook PHP SDK 3.0.1 I tried this FQL query to collect the amount of likes of a photo:
# fql query
$fql = "SELECT object_id FROM like WHERE object_id=" . $photo_id;
# api request
$request = array(
'method' => 'fql.query', 'query' => $fql
);
# run batch request
$likes = $this->facebook->api($request);
# return like count
return count($likes);
I also tried the following Graph API request (Also with Facebook PHP SDK 3.0.1) to collect the amount of likes of a photo:
$likes = $this->facebook->api($photo_id.'/likes');
return count($likes['data']);
Strangely, neither seem to return correct results. I can understand if the API is slightly inaccurate, but according to the API some pictures recieved 100 likes this morning and then 0 likes a few hours later.
Does anyone have any ideas what i might be doing wrong? Do the photo's and their albums need to be public? Do the people who liked the photo need to have a public profile in order to show up in the API? Do i need to request additional permissions?
Any help or suggestions will be greatly appreciated!
Just had the same problem here. The likes seems to be paginated by hundreds by default. Override this setting by using the "LIMIT" query option.
Does anyone have any ideas what i might be doing wrong?
yes, I believe that it is against Facebook policy to use their likes plugin for a contest. See: https://www.facebook.com/promotions_guidelines.php
# fql query
$fql = "SELECT like_info FROM photo WHERE object_id=" . $photo_id;
# api request
$request = array(
'method' => 'fql.query', 'query' => $fql
);
# run batch request
$likeInfo = $facebook->api(array(
'method' => 'fql.query', 'query' => $fql
));
var_dump($likeInfo);die;
=> get like info of photo