How do i retrieve the user if all I have is the accessToken
My use case is retrieve accessToken from mobile app, which is sent to the server and server confirms the token by querying facebook graph api with the accessToken. Your code assumes I already have the user id, on mobile app all I do is retrieve accessToken which is fine because I want the server to validate the token and continue from there.
@Olabayo Do you mean your want to retrieve data of your current user ?
@vooolll Yes without having a user id, by using the accessToken.
Pulled from the facebook php sdk
$fb = new Facebook\Facebook([ 'app_id' => '{app-id}', 'app_secret' => '{app-secret}', 'default_graph_version' => 'v4.0', ]);
// Notice I can retrieve a user without requiring a user id as long as I have his accessToken
try {
// Returns a Facebook\FacebookResponse object
$response = $fb->get('/me?fields=id,name', '{access-token}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$user = $response->getGraphUser();
echo 'Name: ' . $user['name'];
@Olabayo oh, it is easy to solve just pass FacebookUserId("me") instead of FacebookUserId("someid"), and you will get your user, https://github.com/vooolll/facebook4s/blob/master/docs/user.md