codeaf
codeaf

Reputation: 81

Facebook Graph search API

Background:
I'm an employee of a public figure who is constantly getting facebook scam impersonations. I'm going to automate the process of checking facebook for new scams by having a script search facebook each day and report any new users and pages for his name. I'm modifying an old FB app that I created years ago to run the process.

Problem:
I noticed that I can search for "page" on facebook's graph api with my app, but "user" comes back with: "Fatal error: Uncaught OAuthException: A user access token is required to request this resource." I assume this is a permissions error so I try to add an &Access_Token= with all permissions from (https://developers.facebook.com/tools/explorer) to the URL with no luck.

Here's my PHP script:

require '../src/facebook.php';<BR>

$facebook = new Facebook(array(
'appId' => '**I_removed_this_code**',
'secret' => '**I_removed_this_code**'));

$access_token = $facebook->getAccessToken();

$user = $facebook->getUser();
if ($user) {
  try {
    $user_profile = $facebook->api('/me');<BR>
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

$fb_response = $facebook->api('/search?q=**Public_Figure_Name**&type=page'); //<--change this to user and it doesnt work
print_r(array_values($fb_response));

Upvotes: 2

Views: 2506

Answers (2)

Tobi
Tobi

Reputation: 31479

If I try the following in the Graph Explorer, it works without problem:

/search?q=Tom%20Cruise&type=user

https://developers.facebook.com/tools/explorer?method=GET&path=search%3Fq%3DTom%2520Cruise%26type%3Duser&version=v2.2

The Search API is documented at https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search which describes exactly your behaviour (distinction between page and user search).

Upvotes: 0

Amy Codes
Amy Codes

Reputation: 160

The basic issue is that only users an app has access to are either users of the app or (given proper friend permissions) friends of users of the app.

However, if you were to act as you, using an SSO token, 'you' would have a user token and can do graph searches.

PS. I would have added this as a comment but my rep's not high enough.

Upvotes: 2

Related Questions