Get list of top friends for facebook app

只谈情不闲聊 提交于 2019-12-12 03:11:47

问题


I am Creating A facebook that Retrieves 10 Random friends.But I need some code to Retrieve Top friends using comment and like ativity.I used Following code but i get below error

Invalid argument supplied for foreach() 

below is the code i tried so far.

$statuses = $facebook->api('/me/statuses');

    foreach($statuses['data'] as $status){
    // processing likes array for calculating fanbase. 

            foreach($status['likes']['data'] as $likesData){
                $frid = $likesData['id']; 
                $frname = $likesData['name']; 
                $friendArray[$frid] = $frname;
            }

     foreach($status['comments']['data'] as $comArray){
     // processing comments array for calculating fanbase
                $frid = $comArray['from']['id'];
                $frname = $comArray['from']['name'];

}

回答1:


That error message generally happens when your array variable is not set. If you could add line numbers to your code and give the full error message (including line number) it might help.

Can you show a print_r of $statuses['data']?




回答2:


I've been trying to get this to work myself. Found the solution. $facebook->api() is going to return a json array. This is not a valid element for a foreach() statement. You need to use json_decode($statuses) in order to loop through the array in the foreach() statement.

Foreach through JSONArray in PHP



来源:https://stackoverflow.com/questions/9407379/get-list-of-top-friends-for-facebook-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!