简体   繁体   English

使用Facebook PHP SDK返回用户数据

[英]Returning user data using facebook php sdk

I'm trying to figure out the basics of the facebook php sdk. 我试图弄清楚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

$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 . '/$userId'实际上将使用文字字符串/$userId You probably want "/$userId" or '/me' 您可能需要"/$userId"'/me'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM