0
votes

I have an android client, that initiate log-in to facebook, receives access token and other details about the profile.

The android client passes the access_token and details to the Server (PHP).

Both have facebook sdk installed.

When I initiate a FacebookRequest from the PHP, for example '/me/' It's working.

BUT when I initiate a (friends who have installed the APP) FacebookRequest from the PHP '/me/friends'. I get "null".

When I use the graph explorer provided by facebook the result is :

{
  "data": [
  ]
}

Additional information for the helpers:

  • The app contains only two users at the moment, which are friends on facebook.

  • Those users are both administrators of the app.

  • Currently the app is not live\published.

  • We haven't "Start a Submission" in Stats and Reviews as suggested somewhere.

  • We asked for the permission 'user_friends'.

Since everything in stack overflow requires reputation, This is how the permissions look like:

http://i.stack.imgur.com/kURwB.png

Thanks

EDIT:


OK I added two test users, Made them friends of each other, and /me/friends through graph explorer is working for them.

BUT why doesn't it work for non-test-users?

1

1 Answers

0
votes

Okay, So apparently Facebook had a problem providing new Access Tokens. Don't know why, but it provided the same access token, for new Log-Ins.

Now that they fixed that here is a Handy function that I wrote in PHP that will let users Parse Facebook responses, this might come in hand since there is NOTHING explained over the Docs, Google, StackOverFlow.

use Facebook\FacebookSession;
use Facebook\FacebookRequest;

function find_my_facebook_friends($access_token){

require_once 'facebook-php-sdk-v4-4.0-dev/autoload.php';

FacebookSession::setDefaultApplication('app_key','secret_key');


$session = new FacebookSession($access_token);
$request = new FacebookRequest(
    $session,
    'GET',
    '/me/friends'
);

  $response = $request->execute();
  $graphObject = $response->getGraphObject()->asArray();

  return $graphObject;



   }

Usage:

   include_once 'path/to/function.php';
  //You wanna use it, just so the PHP file contains your app_key, secret_key Wont be exposed.

   $access_token = isset($_POST['access_token']) ? $_POST['access_token'] : NULL;
   $facebook_object = find_my_facebook_friends($access_token);


   for($i = 0 ; $i < count($facebook_object['data']) ; $i++){

    $id = get_object_vars($facebook_object['data'][$i]);
    echo $id['id'];
    echo $id['name'];
   //You don't have to echo, you could handle those fields as you wanted.

}

This function refers to a Mobile Client passing his Log In User's access token to the server.

I hope this will save you lots of time!