开发者

How to modify this PHP code to print out list of user interests and other arbitrary data?

开发者 https://www.devze.com 2023-02-22 08:31 出处:网络
If this code prints out the list of user statuses // show statuses $statuses = $facebook->api(‘/me/statuses’);

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!


/me/interests returns an array of JSON strings, each containing id, name, category and create_time

So you'd do it the same way:

foreach($interests[‘data’] as $interest)

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/or friends_interests permissions for it to return anything.


Without getting into the Facebook API specifically, you should use var_dump or print_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

0

精彩评论

暂无评论...
验证码 换一张
取 消