0

I'm creating a custom module in Drupal, that for part of its functionality must fetch posts from a business page. So for simplicity, I'm using fbapp module as a dependency (drupal.org/project/fbapp), so that I can use it's authentication and request functions (fbapp_app_authenticate() and fbapp_graph_request()) without having to worry about the constant facebook graph updates making my own code obsolete.

I've created a facebook app, so authentication should be app token, using appid and app secret. This seems fine and I'm getting back access_token. However, when I try to read posts from a publicly available page (the clients), I get the response:

"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api"

Here's the queries and responses my code produces:

graph.facebook.com/oauth/access_token?client_id=<redacted>&client_secret=<redacted>&grant_type=client_credentials

array(1) {
  ["access_token"]=>
  string(43) "<redacted>|<redacted>"
}

graph.facebook.com/<page_id>/posts?access_token=<redacted>|<redacted>"

string(183) "{"error":{"message":"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100}}"

Can anyone verify a correct way to query a Facebook page programmatically, perhaps there's a setting in the page I'm querying that I need to set (although I can't find anything)?

vim
  • 45
  • 1
  • 9
  • Testing further, the same code can see the app's own posts, so in theory the the code is good. I found the page that I'm trying to access has age restriction of 17+ and location restriction to Australia only. I set my Facebook app to the same restrictions, and got the same result. – vim Jul 09 '15 at 01:59

2 Answers2

0

It looks like everything you have done is correct. The response you got can be (i am not sure) because you got your clients pageid wrong.

  • App Id, secret and graph ID for the page were double checked and triple checked. That was my first assumption too. Thanks for the suggestion. – vim Jul 10 '15 at 00:59
0

If page restrictions apply, the page's feed can only be retrieved with an user access token as far as I know (because FB needs to evaluate the visibility criteria, and setting your app to the same restrictions doesn't help here):

See

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • Apart from a user access token, a page access token will work as well (for pages that you have admin access to only, obviously) – so for any server-side app that might be the more convenient way, since page access tokens can be extended to have no default expiry. – CBroe Jul 09 '15 at 12:42
  • @CBroe Are you sure that page access tokens would also work if there are access restrictions? I think the only thing that works are user access token, because how should FB otherwise evaluate the filter on location *and* age? – Tobi Jul 09 '15 at 13:29
  • Yes, since page access tokens can only be granted by someone with admin access to the page – and they would be able to see all posts on the page, no matter what restrictions might apply. (Whether that’s what one would _want_, is another question. Maybe you’d want your app to mirror to the viewing user what _they_ would see if they visited the page directly. In that case, their user access token should be used, because only then the restrictions or targeting options would be applied. […] – CBroe Jul 09 '15 at 13:34
  • […] Using the page access token to fetch the posts would show all posts, regardless of whether the current app user could see them on the page or not.) – CBroe Jul 09 '15 at 13:35
  • @CBroe That would make sense, but I guess this is nowhere documented, is it? – Tobi Jul 09 '15 at 13:51
  • Well, it _kinda_ is – https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed#readperms “• A user access token is required to retrieve posts visible to that person. • A page access token is required to retrieve any other posts” at least _implies_ this. – CBroe Jul 09 '15 at 13:58
  • @CBroe I'd interpret this completely different :-) ...any **other** posts... is kind of misleading IMHO – Tobi Jul 09 '15 at 14:22
  • If you think the phrasing on that one could be improved, feel free to file a documentation bug. (From my experience, they usually react quite welcoming to those, if you can describe why you find something confusing, and how it could possible be put better.) – CBroe Jul 09 '15 at 14:28
  • But the page access token does give you access to all page posts, no matter what their visibility to an individual user might be – that is a fact, trust me. (And anything else would not make much sense really, since a page access token is supposed to enable you to ”manage” your page via an app, including the page’s feed – and if it would “keep” certain posts from you, it could not really fulfill that purpose.) – CBroe Jul 09 '15 at 14:29
  • Thanks a lot for the help! That solved it. page access token did the trick. I was able to generate a programmatically generate a long lasting token, following this thread http://stackoverflow.com/questions/12168452/long-lasting-fb-access-token-for-server-to-pull-fb-page-info – vim Jul 10 '15 at 09:19