如何修改此 PHP 代码以打印出用户兴趣列表和其他任意数据?
如果此代码打印出用户状态列表,
// show statuses
$statuses = $facebook->api(‘/me/statuses’);
foreach($statuses[‘data’] as $status)
{
echo $status["message"], "<br />";
}
我该如何修改它以打印兴趣?我在想——>
// show interests
$interests = $facebook->api(‘/me/interests’);
foreach($interests[‘???’] as $interest)
{
echo $interest["???"], "<br />";
}
良好参考
我认为这是正确的想法,但我不知道该将什么作为 $interests
和 $interest
的参数,并且无法找到 FB Help 的 很感激!
If this code prints out the list of user statuses
// show statuses
$statuses = $facebook->api(‘/me/statuses’);
foreach($statuses[‘data’] as $status)
{
echo $status["message"], "<br />";
}
How do I modify it so that it prints the interests ? I am thinking-->
// show interests
$interests = $facebook->api(‘/me/interests’);
foreach($interests[‘???’] as $interest)
{
echo $interest["???"], "<br />";
}
I think this is the right idea but i don't know what to put as the arguments for $interests
and $interest
and can't find a good reference form FB
Help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
/me/interests
返回一个 JSON 字符串数组,每个字符串包含id
、name
、category
和create_time
所以你可以用同样的方式来做:
然后你只需要查看
$interest
中的 JSON 并提取你想要的内容。另请注意,您的应用需要用户授予
user_interests
和/或friends_interests
权限才能返回任何内容。/me/interests
returns an array of JSON strings, each containingid
,name
,category
andcreate_time
So you'd do it the same way:
You will then need to simply look at the JSON in
$interest
and extract what you want.Also note that your app needs the user to grant the
user_interests
and/orfriends_interests
permissions for it to return anything.无需专门进入 Facebook API,您应该使用
var_dump
或print_r
来确定$interests
变量的结构,然后您就会知道循环什么。我将这种努力视为一种基本的调试/探索性实践,您在寻求帮助之前应该尝试一下。var_dump 文档: http://php.net/manual/en/function.var- dump.php
print_p 文档: http://php.net/manual /en/function.print-r.php
Without getting into the Facebook API specifically, you should use
var_dump
orprint_r
to ascertain the structure of the$interests
variable, then you'll know what to loop. I would regard such effort as a basic debugging/exploratory practice that you ought to have tried before seeking help.var_dump docs: http://php.net/manual/en/function.var-dump.php
print_p docs: http://php.net/manual/en/function.print-r.php