开发者

How to subscribe to real-time updates for a Facebook page's wall

Facebook's real-time updates docs now say that you can get the feed for a开发者_运维百科 page:

You can subscribe to the page's feed in the same way you subscribe to a user's feed - the subscription topic should be 'user' and the subscription field should be 'feed'

My understanding of this is that I need to post to the graph API to subscribe as such:

curl -d \
"object=user&fields=feed&callback_url=$CALLBACKURL&verify_token=$SECRET" \
"https://graph.facebook.com/$PAGEID/subscriptions?access_token=$OAUTHTOKEN"

(This is a bash script.) Here $CALLBACKURL is set up correctly following their example code. (At least I think it's correct -- I can successfully add subscriptions with it.) The $OAUTHTOKEN is the one for my Facebook App.

And the $PAGEID is the facebook object id of the page I'd like to get realtime updates for.

When I do this, the call appears to work -- no error message. My callback gets called. But I certainly don't get notified when something happens on the page's feed.

So what's missing? Does the page need to install the app whose oauth token I'm using? Or do I somehow need to get an oauth token for the page itself by logging in as the page?


I do not know if this can help you but I'll tell you where I am for real-time update page feed:

(permissions : manage_page,offline_access,read_stream)

  1. your application must be linked to the page (then install the application but not required to have a tab ex. create tab https://graph.facebook.com/PAGE_ID/tabs?app_id=APP_ID&method=POST&access_token=PAGE_ACCESS_TOKEN and delete tab TAB_ID=PAGE_ID.'/tabs/app_'.APP_ID; https://graph.facebook.com/TAB_ID?method=DELETE&access_token=PAGE_ACCESS_TOKEN)

    
    function page_access_token($page_id,$access_token){
    $page_token_url="https://graph.facebook.com/" . $page_id . "?fields=access_token&" . $access_token; $response = file_get_contents($page_token_url); $resp_obj = json_decode($response,true); $page_access_token = $resp_obj['access_token']; return $page_access_token; }

    function page_tabs_create($page_id,$app_id,$page_access_token){

    $page_settings_url = "https://graph.facebook.com/" . $page_id . "/tabs?app_id=".$app_id."&method=POST&access_token=" . $page_access_token; $response = file_get_contents($page_settings_url); $resp_obj = json_decode($response,true); return $resp_obj; }

    function page_tabs_delete($tab_id,$page_access_token){

    $page_settings_url = "https://graph.facebook.com/".$tab_id."?method=DELETE&access_token=" . $page_access_token; $response = file_get_contents($page_settings_url); $resp_obj = json_decode($response,true);

    return $resp_obj; }

  2. Subscription: to subscribe must be like a "user" and therefore object = user fields = feed but you have to add new fields because otherwise it receives the comments and likes the wall so you must add "status" in order to receive the articles posted (my problem is to get other content such as links I have managed to add "link" as fields but I am not receiving notifications when a link is posted)

    $param = array ('access_token' => $ access_token, 'object' => 'user', 'fields' => 'feed, status, link' 'callback_url' => 'http:// ******** fbcallback.php' 'verify_token' =>'***********', 'include_values' => 'true');

    POST https://graph.facebook.com/APP_ID/subscriptions

my English is not very good but I hope it will help you, on my side I'm still looking for really all updates to the wall (links, video ...)


I have been researching on this and i am getting the pushes for pages too.

  1. while subscribing make sure that object = user and fields = feed, status is present.

  2. Make sure that application is added to your page, then only you will receive the update.

  3. Response received from facebook is as below :-

{"entry":[{"id":"*******","uid":"*****","time":1332940650,"changed_fields":["status"]}],"object":"user"}

where **** is my pageId.

The above push is received on adding a new post , as you can see the changed_feild is status , but when we post on wall the changed_fields comes as feed. Below link helped me in receiving pushes for the page.

http://bugs.developers.facebook.net/show_bug.cgi?id=18048


Firstly, subscription to real-time update for page/feed doesn't work. See: http://bugs.developers.facebook.net/show_bug.cgi?id=18048

Does the page need to install the app whose oauth token I'm using?

Yes

Or do I somehow need to get an oauth token for the page itself by logging in as the page?

If i correctly understand you, you need only app access_token https://graph.facebook.com/oauth/access_token?client_id=your_app_id&client_secret=your_secret&grant_type=client_credentials


I first started reading the docs about real-time updates thinking that it could delivery the actual data. But, as I realized, that's not the purpose.

Real-time updates are just to tell you that something has changed, and once it happens, you can call the api with the conventional method.

Also, seems like there's an error on this part the subscription topic should be 'user' and the subscription field should be 'feed'. The subscription topic, actually, should be 'page'. (Have you thought the same?)

And by subscribe on page feed as the same as user feed, means that you can get update notifications, not the data itself.

Not sure if this is a common mistake, but I'm posting it just in case.

--

Currently I'm working on a data mining tool that will need real-time updates. But first, I'm focused on the data itself, so I can't post any examples yet. (I'll edit this answer when implementing this part)

What I can say about your issue is:

1) Look that your $PAGEID isn't correct. Actually it's your APPID instead.

2) After subscribing, have your subscription appeared on the list when calling https://graph.facebook.com/<app-id>/subscriptions?access_token=... ?

3) With user subscription, does it work? Or is it just with pages?


For this you need to set up an endpoint URL that receives both HTTP GET (for subscription verification) and POST (for actual change data) requests from Facebook.

Then you should make a POST to the graph API url https://graph.facebook.com/<app-id>/subscriptions?access_token=<access_token> to subscribe, and be ready to handle the verification request.

Then to list subscriptions, just perform a GET request on the same url, https://graph.facebook.com/<app-id>/subscriptions?access_token=<access_token>, which returns a JSON-encoded content that lists your subscriptions, up to one per object type.


Before you start waiting for the notifications you should check if the URL is actually being hit or not by FB

Check The Output of Following:

"https://graph.facebook.com/".FACEBOOK_APP_ID."/subscriptions?".$appToken."&client_secret=".FACEBOOK_SECRET;

This shall return the callback_url if set correctly !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜