如何在 Facebook 粉丝页面上显示用户名
我已经用谷歌搜索了很多地方,但我无法弄清楚这一点,所以非常感谢任何帮助。
我有一个 iframe Facebook 粉丝页面,希望用户名与一些文本一起显示。 这是我的代码:
<?
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '...',
'secret' => '...',
'cookie' => true
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
?>
<? echo $user['name']; ?>
它只回显“0”
我一直在尝试使用 php sdk 来做到这一点,但如果有一种方法可以使用 javascript 来做到这一点,那也很好。
I've googled everywhere for this and I can't figure this out, so any help is much appreciated.
I have an iframe Facebook fan page and want the username to show up with some text.
This is the code I have:
<?
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '...',
'secret' => '...',
'cookie' => true
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
?>
<? echo $user['name']; ?>
It only echoes "0"
I've been trying to do this with the php sdk, but if theres a way to do it with javascript that's fine too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
示例代码中的
$user
是一个包含 Facebook 用户 ID 的字符串。您可能想打印
$user_profile['name']
$user
in your sample code is a string containing user id from Facebook.You probably wanted to print
$user_profile['name']
您还可以执行以下操作:
然后您将拥有:
You can also do something like:
And then you'll have:
这对我有用
您还可以使用
uid 将是应用程序用户的 id 的位置。
This works for me
You can also use
where uid will be id for the app user.