vForums Support > vForums :: Support :: > API Error

API Error - Posted By dog199200 (dog199200) on 11th Feb 11 at 11:19am
Forum URL: http://www.shiningashes.vforums.us
Site URL: http://www.shiningashes.net/

Problem:
Code:
 
  1. Warning: Invalid argument supplied for foreach() in /home/REMOVED/public_html/index.php on line 71
 


Ross,

For some reason since the migration to the new server i've been getting this error because of the API system. I can no longer login via my website, or anything else. I had changed nothing within my programming. Here is the codes i've been using incase its a problem resulting in something being changed within the API:

Code Giving The Error:
Code:
 
  1. <?php
  2. $news_articles = $vforums_api -> get_recent(Array(
  3. "board" => "publicupdates",
  4. "mode" => "topics",
  5. "show_locked" => "1",
  6. "allow_all" => "1",
  7. "max" => "1"
  8. ));
  9. foreach($news_articles as $post) {
  10. ?>    
  11.  
  12. <div class="content">
  13.     <h2>News</h2>
  14.     <div class="text">
  15.         <div class="right"><?=date('l dS \of F Y', $post['timestamp']);?></div>
  16.                          <h4 class="subject"><u><?=$post['subject'];?></u></h4>
  17.                          <blockquote><?=$post['message'];?></blockquote>
  18.                          <div style="text-align : right;">~ <b><?=$post['display_name'];?></b></div>
  19.     </div>
  20. </div>
  21.  
  22. <?php
  23. }
  24. ?>
 


API Include Statement:
Code:
 
  1. <?php
  2. include_once('/home/REMOVED/public_html/includes/vforums_api.php');
  3. $vforums_api = new vforums_api('shiningashes.vforums.us', 'REMOVED');
  4.  
  5. $user_info = $vforums_api -> login_user("user", "pass");
  6. $logged_in = $user_info? true : false;
  7. ?>
 



Then i'm calling it into every page using:
Code:
 
  1. include("/home/REMOVED/public_html/includes/forumdata.php");
 



Re: API Error - Posted By Ross (admin) on 11th Feb 11 at 11:32am
Should be good now.

BTW, do not post your API key anywhere that anyone can see it. It effectively gives someone access to all areas of your forum. I would recommend you change it ASAP.

Re: API Error - Posted By dog199200 (dog199200) on 11th Feb 11 at 11:34am
Ah yeah, forgot to remove it, sorry i'm tired. And thanks for fixing it. What was wrong if you don't mind me asking

Re: API Error - Posted By Ross (admin) on 11th Feb 11 at 1:28pm
Posted By dog199200 on 11th Feb 11 at 11:34am
 
Ah yeah, forgot to remove it, sorry i'm tired. And thanks for fixing it. What was wrong if you don't mind me asking


Lets just say there was nothing wrong on your side {Smile}

Re: API Error - Posted By dog199200 (dog199200) on 12th Feb 11 at 12:35am
I kind of figured that considering nothing got changed and it got fixed {Tongue Out}

Re: API Error - Posted By dog199200 (dog199200) on 13th Feb 11 at 2:53am
Gah, Ross same error as above, same site:

"Invalid argument supplied for foreach() in /home/REMOVED/public_html/spanel/staffm.php on line 44"

The members list function isn't working

Re: API Error - Posted By Ross (admin) on 13th Feb 11 at 1:20pm
Can you provide me with an example of a page this is happening on or the code you are using to call the API. There is nothing in the error log this time.

Re: API Error - Posted By dog199200 (dog199200) on 14th Feb 11 at 1:24pm
Ok here is the code. I cant give you a link to the page since the page is private. I just know I had it working before the server move and after it stopped working.

Code:
 
  1. <?php
  2. $member_list = $vforums_api -> get_members($max = "100");
  3.  
  4. echo "<table cellpadding=\"5\" cellspacing=\"1\" border=\"1\" width=\"100%\">
  5.  
  6. <tr>
  7.     <td width=\"30%\">
  8.         <h4>NAME</h4>
  9.     </td>
  10.     <td width=\"30%\">
  11.         <h4>RANK</h4>
  12.     </td>
  13.     <td width=\"30%\">
  14.         <h4>Modifications</h4>
  15.     </td>
  16. </tr>
  17.  
  18. ";
  19.  
  20. foreach($member_list as $member) {
  21. ?>    
  22.  
  23. <tr>
  24.     <td width=\"30%\">
  25.         <a href="http://www.shiningashes.vforums.us/profile/<?=$member['user_name'];?>"><?=$member['display_name'];?></a>
  26.     </td>
  27.     <td width=\"30%\">
  28.         <?=$member[rank][1][name];?>
  29.     </td>
  30.     <td width=\"30%\">
  31.         Edit - <a href="mailto:<?=$member['e-mail'];?>">Email</a>
  32.     </td>
  33. </tr>
  34.  
  35. <?php
  36. }
  37. echo "</table>";
  38. ?>
 


Re: API Error - Posted By Ross (admin) on 14th Feb 11 at 1:50pm
A couple of bits to change:

$member_list = $vf -> get_members($max = "100");

to

$member_list = $vf -> get_members(Array("max" => "100"));


<?=$member['e-mail'];?>

to

<?=$member['email'];?>


and

<?=$member[rank][1][name];?>

to

<?=$member['rank'][1]['name'];?>


Other than that, should now be working.

Re: API Error - Posted By dog199200 (dog199200) on 14th Feb 11 at 10:15pm
Ah ok, thats weird because it was working just fine in the past and I didn't change anything. Oh well thanks Ross, it works now.