Facebook API: Determine if Facebook Page is published / unpublished

孤街浪徒 提交于 2019-12-05 05:45:05
Luke Rehmann

Punch this in under FQL query on http://developers.facebook.com/tools/explorer

SELECT page_id, name, username, is_published
   FROM page 
   WHERE page_id IN 
      (SELECT page_id FROM page_admin WHERE uid = me()) 
   AND is_published=""
   ORDER BY fan_count DESC

That will select all pages in your account and check if they are published, returning all unpublished pages in a list.

It turns out that there's no known way to check specifically whether a Page is published / unpublished. The graph API http://graph.facebook.com/{page_id} will return false if any of the following is true:

  • Page is unpublished
  • Page has country restrictions
  • Page has age restrictions

If and only if none of the above settings apply, then http://graph.facebook.com/{page_id} will return an object graph.

Note: I'm assuming that an access token with manage_pages permission is not used for the API calls above. With a proper access token, https://graph.facebook.com/{page_id} will return the object graph, regardless of whether the Page has restrictions or not.

Waseem

You can use following but it works when you have manage_pages permission on the page http://graph.facebook.com/{page_id}/settings

try this code with the manage_pages permission

FB.api('/me/accounts', function (resp) {
                        //var txtpageid = 
                        if (txtpageid != '') {
                            FBactualID = '';
                            for (var i = 0, l = resp.data.length; i < l; i++) {
                                var page = resp.data[i];
                                if (page.id == txtpageid) {
                                    FBactualID = txtpageid;
                                    varFBResponseFlag = true;
                                    //alert('inside the page id validation');
                                }
                            }
                        }
                        getCheckedValue(FBactualID);

                    });

Fetch the page using the Graph API (using cURL as a system call, HTTPClient with Rails, or $.getJSON() with jQuery, for example) with http://graph.facebook.com/PAGE_ID. Unpublished pages will return false, and published ones will return a JSON array of information.

This does not require any access tokens or permissions.

Using cURL (command line)

$ curl http://graph.facebook.com/UNPUBLISHED_PAGE_ID
false
$ curl http://graph.facebook.com/PAGE_ID
{"id":"1234","name":"Test Page","picture":....

Using HTTPClient (with Rails)

HTTPClient.get("http://graph.facebook.com/UNPUBLISHED_PAGE_ID").body
# false
HTTPClient.get("http://graph.facebook.com/PAGE_ID").body
# "{\"id\":\"1234\",\"name\":\"Test Page\",\"picture\"....

Using $.getJSON() (jQuery)

$.getJSON("http://graph.facebook.com/UNPUBLISHED_PAGE_ID", function (data) {
  console.log(data); // false
}
$.getJSON("http://graph.facebook.com/PAGE_ID", function (data) {
  console.log(data); // JSON Object with page info
}

You will only be able to see the page if you use an access_token that can see the page in the request.

You will always see only the pages you would see with the access_token user on facebook.

Using my own access_token in the above examples for example does still yield falsefor AjiRestaurant but i will get informations for KeystoneLight just fine as my account matches the restrictions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!