Facebook Fan Page vs. Twitter Streaming API - facebook

What is the counterpart of Twitter Streaming API for Facebook Fan Page?
How can i get real time updates from a Facebook Fan Page?

You have to use the realtime api from facebook : http://developers.facebook.com/docs/api/realtime/
To do what you ask, you must subscribe to page objects and their feed connection.
To add a subscription you have to send a POST request to :
https://graph.facebook.com/<app-id>/subscriptions?access_token=...
And for that you need an access token that you can get at :
https://graph.facebook.com/oauth/access_token?client_id=<app-id>&client_secret=<app-secret>&grant_type=client_credentials
The fields that have to be in the POST data are :
object - The type of the object to monitor, e.g. “user” or “permissions”. You will monitor all objects of that type; for example, all users of your application.
fields - A comma-separated list. This is a list of properties or connections on the specified object. For example, to monitor changes to user's name, picture, friends, and News Feed, you would specify “name,picture,friends,feed”
callback_url - A callback URL to which Facebook will post subscription updates.
And you can specify
verify_token - A subscriber-provided opaque token that will be echoed back in the verification request to assist the subscriber in identifying which subscription request is being verified. If this is not included, no token will be included in the verification request. This is from the PubSubHubbub spec.
Once your callback url has been verified, you will receive updates when data change in the feed of the page on your callback url as json objects, here is an example for a user :
{
"object": "user",
"entry":
[
{
"uid": 1335845740,
"changed_fields":
[
"name",
"picture"
],
"time": 232323
},
{
"uid": 1234,
"changed_fields":
[
"friends"
],
"time": 232325
}
]
}
You can also do GET and DELETE on the same URL to get the list of your subscriptions, and to delete subscriptions.
But all the details are in the facebook doc

Related

FB Graph API is not returning user object in post's comments, likes, reactions

I've FacebookApp [ type: business ] which fetches all posts, post-comments, and post-likes from the owned Facebook pages.
Verified permissions are ['pages_show_list', 'pages_read_user_content']
When I'm fetching the post and their comments/likes then the user-object is missing in the response body.
Sample JSON
API : https://graph.facebook.com/v2.12/<PAGE-ID>/? \
fields=posts{message, comments{message, from{id, name, link}},reactions{from{id, name, link}}} \
&access_token={{pagetoken}}
response body sample :
...
"message": "For cancer awareness month we are sharing stories of survivors! \n\nManorama is sharing story ... Cancer Campaign (India)",
"comments": {
"data": [
{
"message": "Thank u so much to the entire team.",
"id": "420757949533461_421416076134315",
// USER OBJECT IS MISSING : [id, name]
},
{
"message": "Thank u for sharing ma's story with all!",
"id": "420757949533461_421407146135208",
// USER OBJECT IS MISSING : [id, name]
}
],
...
I'm not sure what is wrong with the above API call because the API call is working fine with TestPage and TestUser. Do I need to ask for some additional permissions from Facebook?
Facebook Graph api does not return user's name anymore by calling this endpoint.
There is one solution you can try: use hooks.
Set a page webhook to retrieve all the comments written on your page. Find the documentation here: https://developers.facebook.com/docs/pages/realtime
The comments' data you'll receive from facebook will contain a name

Information in Feed Weebhook

I subscribed to feed webhook and I ve receiving posts everytime the user navigate and search something.
Is the expected behavior because documentation say:
Describes changes to most sections of the user's profile, such as About, Photos, Posts, Friends, and Likes
The json that I receive is:
{
"entry":
[
{
"time": 542196889466880,
"id": "0",
"changed_fields": ["feed"],
"uid": "XXXXXXXXXXXXX"
}],
"object": "user"
}
Can you provide JSON of Facebook you receive when the user navigate and search something?
I'm using webhook. I've only subscribed to webhook feed, and I only receive event data when user comment/post/reaction in my page.

Facebook API: (#100) No matching user found

I spent whole days to try to figure out this error, I also notice there are similar questions with the same message, but I'm totally not sure I find the answer in there, so if someone could point out or give any tip into my problem, I totally appreciate that.
I'm making the request to send a message from a Facebook page A to a user X (by userId) who makes a comment on a post of FB Page A, through a testing FB App name MyApp. I am trying this on Facebook Graph Explorer.
I got the user Id by fetch the list of comments in a post in the Facebook Page, but I totally could not send the message.
Here is the error
{
"error": {
"message": "(#100) No matching user found",
"type": "OAuthException",
"code": 100,
"error_subcode": 2018001,
"fbtrace_id": "H3yMO0RWaDy"
}
}
Here is the my track
MyApp has been setup webhook OK, because it is not published yet for the testing purpose (unapproved app), so I have to add the user X account into tester pool of MyApp (the message that I try to send is also this user X)
I logged into user X to make a comment on a post in the FB Page A
On Graph Explorer, I selected Application: MyApp, and get Page Access Token of FB Page A, I performed two following requests
3.1 /{page_id}_{post_id}?fields=comments
With this, I can get the list of existing comments in FB Page A, here is the output:
{
"comments": {
"data": [
{
"created_time": "...",
"from": {
"name": "User X",
"id": "123456789" // this is the user Id that I would take to send the message to
},
"message": "Sample comment from User X",
"id": "..." // {page_id}_{post_id}
}
],
"paging": {
....
}
},
"id": "..." // {page_id}_{post_id
}
}
3.2 {page_id}/messages: I am trying to send a message from FB Page A to user X with the user Id that I got from 3.1 step
recipient: {id: "123456789"} // there seems be a problem with this id that I got from step 3.1, FB cannot find the user id with this number
message: {text: "hello"}
I'm also acknowledged about the app/page scoped id for user.
I have already subscribed MyApp to the FB Page A with API (/{page_id}/subscribed_apps)
Facebook API v2.10
I have no clue what's wrong.
I figured it out. Facebook Messenger Platform use paged scope user id, but what I were using is app scope id. They are different.
Here is official doc from Facebook about how to get the paged scope id
The id must be an ID that was retrieved through the Messenger entry
points or through the Messenger webhooks (e.g., a person may discover
your business in Messenger and start a conversation from there.
These IDs are page-scoped IDs (PSID). This means that the IDs are
unique for a given page.
If you have an existing Facebook Login integration, user IDs are
app-scoped and will not work with the Messenger platform.
The solution is subscribing MyApp to the FB Page (what I've already done) to get the webhook to work, where I will get the page scope id from the message of user.
Furthermore, detail of how to setup the subscription found here
http://ukimiawz.github.io/facebook/2015/08/12/webhook-facebook-subscriptions/

Facebook real time update for user and page

I have setup realtime facebook update for both user and page. Whenever user updates his status, I get request on my server about the change. The data I get from facebook post call is like below.
{
"object":"user",
"entry":[
{
"uid":"10152689315982483",
"id":"10152689315982483",
"time":1427362347,
"changed_fields":[
"feed"
]
}
]
}
But I did not get any call from facebook when admin of a page update its status.
I followed the below steps to get the realtime facebook update.
Subscribe user/page to get updates with access token.
graph.facebook.com//subscriptions?object=user&fields=feed&verify_token=&method=post&callback_url=htps://serverurl/realtime.php
To get the list of subscription
graph.facebook.com//subscriptions
From this call I get both user and page data.
{
"data": [
{
"object": "user",
"callback_url": "https://serverurl/realtime.php",
"fields": [
"feed"
],
"active": true
},
{
"object": "page",
"callback_url": "https://serverurl/realtime.php",
"fields": [
"feed"
],
"active": true
}
]
}
I also added the app to page-tab but still not getting the updates for page. Could anyone tell me what I am missing?
Do an http GET on
https://graph.facebook.com/v2.3/{page-id}/subscribed_apps?access_token=PAGE_ACCESS_TOKEN
If your app is not listed, you need to "install it" (this is an alternative installing the app as a page tab app). Do this by issuing a post request to the same url. Eg with curl,
curl -X POST "https://graph.facebook.com/v2.3/{page-id}/subscribed_apps?access_token=PAGE_ACCESS_TOKEN"
You don't need to supply any parameters since the id of the app you wish to install is inferred from the access token.
If /subscribed_apps already includes your app id, you may be experiencing a bug and should report it at http://developers.facebook.com/bug

Commenting on Facebook Page Ratings (Reviews) via Graph API

Long time lurker first time poster...
We are working with Facebooks API's to integrate into our web application and we are able to pull a Companies Page Rating via the {open_graph_story} parameter in the {page-id}/ratings section, however we cannot find a way to comment/reply to the rating. The documentation states:
"If a person has rated your page and a story has been generated, you can follow up with the person by posting to the story's comment node." (https://developers.facebook.com/docs/graph-api/reference/v2.0/page/ratings)
however when we pull the variables we retrieve no ID to reference for a comment. This is what we receive back from our authenticated account:
"data": [
{ "created_time": "2014-07-16T05:52:50+0000", "reviewer": { "id": "100000237096397", "name": "Romey Salazar" }, "rating": 5, "review_text": "Great job guys!!!!" } ],
Does anyone know how to retrieve the id for the rating itself so we can append a comment via API? Or some other way to reply/comment to a FB Page Rating?
Thanks!
When you have some ratings/review comments on your page and if you want to post comment to individual review comments as the Page Owner, you can follow the steps below.
1) Below request returns the json object of rating and reviews.
https://graph.facebook.com/v2.9/{YOUR_PAGE_ID}/ratings?field=open_graph_story&access_token={YOUR_PAGE_ACCESS_TOKEN}
The response json will contain ID field for each and every rating/review comments.
2) Using the ID, trigger the below request to post a comment on the rating as the Page Owner. You will need Page access token with manage_pages and publish_pages privilege.
https://graph.facebook.com/v2.9/{ID_OF_THE_RATING}/comments?message=Thanks for your rating&access_token={YOUR_PAGE_ACCESS_TOKEN}
These requests can be tested using Facebook Graph API Explorer
You need to request the open_graph_story field with the ratings endpoint. This will return the open_graph_story data which includes an id. You can then post to the comments endpoint of this story.
You have to make http get request on
https://graph.facebook.com/v2.9/{PageID}/ratings?fields=open_graph_story&access_token={PageAccessToken}
to get detailed response.
Make sure the parameter is "fields" not "field"