问题
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?
回答1:
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.
回答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.
回答3:
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);
});
回答4:
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
}
回答5:
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 false
for AjiRestaurant but i will get informations for KeystoneLight just fine as my account matches the restrictions.
来源:https://stackoverflow.com/questions/8840569/facebook-api-determine-if-facebook-page-is-published-unpublished