I'm trying to figure out the basics of the facebook php sdk. I'm using the pretty simple code below...
<?php
include 'facebook.php';
$app_id = "my_id";
$app_secret = "my_secret";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$userId = $facebook->getUser();
echo $userId;
$userInfo = $facebook->api("/$userId");
echo $userInfo['name'];
?>
When I ask for the $userId with
$userId = $facebook->getUser();
echo $userId;
I get the correct value. However when I try to take the next step and retrieve the logged in user's name with :
$userInfo = $facebook->api("/$userId");
echo $userInfo['name'];
nothing is returned. Does anyone see my error? Thanks!
'/$userId'
will actually use the literal string /$userId
. You probably want "/$userId"
or '/me'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.