Question

I have a web service that servers Android, IOS and Windows Phone. Each app connects to Facebook using native SDK and passes the fb_user_id and access_token when performs API's requests. The API should retrieve the user and friends details and save them on MySQL.

The system works fine, except that it can't return friend's retionship, location and birthday.

$fb = new Facebook([
    'appId' => my_app_id,
    'secret' => my_app_secret
]);

$r = $fb->api("$fb_user_id/?fields=friends.fields(relationship,birthday,location)&access_token=$access_token");
var_dump( $r );

My app on Facebook has friends_relationships, friends_location and friends_birthday permissions. When we test using a Facebook user setted as developer, the app returns all the information, but when a non-developer uses we can't return those informations.

Any idea?

Was it helpful?

Solution

I figured what happened!

Facebook's SDK generates a token for /me. In PHP I was calling fb_user_id?fields=friends.fields(id,name,birthday,etc). But requests with /fb_user_id can't return info with a /me generated token.

It works when used directly on browser https://graph.facebook.com/me?fields=friends.fields(id,name,birthday,etc), but fails when called by Facebook's PHP class:

An active access token must be used to query information about the current user.

My solution:

    $url = "https://graph.facebook.com/me?fields=id,name&access_token=$this->access_token";
    $this->me = file_get_contents ( $url );                 
    $json = json_decode($this->me, true);

For further information, checkout this answer. New ideas are welcome.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top