7

What is a reliable way to check whether a Facebook Page is published or unpublished using the graph API? I currently do this:

http://graph.facebook.com/{page_id}

and check if the return value is "false". If it's false, I conclude that it's unpublished and if it returns a graph object, then conclude that it's published. But I'm noticing now that a lot of published pages return "false" from the above request.

Here's an example:

this page is published: http://www.facebook.com/AjiRestaurant

but these requests return false: http://graph.facebook.com/104433516257517 (using page Id) http://graph.facebook.com/AjiRestaurant (using page username)

What is the best way to check whether a Page is published?

Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
  • I'm looking at the settings for my pages and cannot figure out how you can set public/private other than by the top check box on the page that reads: "Page Visibility [] Unpublish page (only admins can see this page)". Is this what you want to query? – DMCS Jan 12 '12 at 19:11
  • Yes, that's the one. I'd like to detect when a page is "unpublished". I probably used the wrong words "private/public", and should have used "published / unpublished". I'll update my question now. – Johnny Oshika Jan 12 '12 at 20:21
  • http://www.facebook.com/AjiRestaurant does not show up for me. – Julio Santos Jan 18 '12 at 10:13
  • Hi Julio, are you logged in to Facebook? – Johnny Oshika Jan 19 '12 at 18:06
  • Yes I am. Still can't see it. Does the page have country restrictions? – Julio Santos Jan 19 '12 at 22:13

5 Answers5

3

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Luke Rehmann
  • 514
  • 5
  • 12
  • Nice! You solved this one. It looks like 'is_published' is also now available through the graph API: http://developers.facebook.com/docs/reference/api/page/ – Johnny Oshika Mar 13 '13 at 16:27
  • As of August 8, 2016, FQL will no longer be available and cannot be queried. – Tal Weiss Feb 19 '17 at 12:44
2

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.

Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
0

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);

                    });
Chandru velan
  • 136
  • 1
  • 3
  • 21
Waseem
  • 43
  • 7
  • I don't quite follow what you're doing. You're iterating through all of the user's Pages and checking whether the Page ID matches the Page ID that I'm trying to check and then storing it in FBactualID. Why would you need to do this? And then you're calling getCheckedValue(). What does that method do? – Johnny Oshika Jan 19 '12 at 18:36
0

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
}
Julio Santos
  • 3,837
  • 2
  • 26
  • 47
  • 1
    This is incorrect. Pages with restrictions will also return false, as is the case with pages that promote alcohol. Try http://graph.facebook.com/KeystoneLight and you'll see that it returns false, even though the page is published. – Jeff Sherlock Jan 19 '12 at 17:20
  • Jeff is right. I just came to the same conclusion and updated my original question with this info. – Johnny Oshika Jan 19 '12 at 18:48
  • Thanks Julio for your answer. It's not 100% correct, but it's still a very informative answer, so you get the bounty. – Johnny Oshika Jan 24 '12 at 06:24
0

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.

bardiir
  • 14,556
  • 9
  • 41
  • 66