83897

Get list of top friends for facebook app

Question:

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']; }

Answer1:

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']?

Answer2:

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.

<a href="https://stackoverflow.com/questions/5444260/foreach-through-jsonarray-in-php" rel="nofollow">Foreach through JSONArray in PHP</a>

Recommend

  • display list of friend user is not showing all users
  • Zend DB Select with multiple table joins
  • django - can't see the uploaded media files from apache
  • iOS, How to check whether the user likes a facebook page or not?
  • Python PIL to extract number from image
  • NHibernate manually control fetching
  • Can't remove headers after they are sent
  • Optimizing the print function in Matlab
  • Security issues with PHP's Readfile method
  • Stop Bash Script if Hive Fails
  • How to use JavaScript to determine whether a file exists in a directory?
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • How to attach a node.js readable stream to a Sendgrid email?
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Deselecting radio buttons while keeping the View Model in synch
  • Getting last autonumber in access
  • Counter field in MS Access, how to generate?
  • Incrementing object id automatically JS constructor (static method and variable)
  • How to check if every primary key value is being referenced as foreign key in another table
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Hazelcast - OperationTimeoutException
  • jquery mobile loadPage not working
  • Rearranging Cells in UITableView Bug & Saving Changes
  • RestKit - RKRequestDelegate does not exist
  • How to delete a row from a dynamic generate table using jquery?
  • Revoking OAuth Access Token Results in 404 Not Found
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Benchmarking RAM performance - UWP and C#
  • Angular 2 constructor injection vs direct access
  • embed rChart in Markdown
  • How to stop GridView from loading again when I press back button?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?