0

Im having a problem getting my desired output out of a function. I see that its returning the proper data when i do a 'var dump'. However, it either does not show anything or i'm getting invalid argument errors / 'Object of class stdClass could not be converted to string'.

Here is the function

     public function searchUser($name, $limit = 0) {
     return $this->_makeCall('users/search', false, array('q' => $name, 'count' => $limit));
     }

and my code is calling it like this:

    $usearch=$_POST['usersearch'];



    $result = $instagram->searchUser($usearch);

....

    <div id="searchresults">

    <h4> Search result for <?php
     echo $usearch;
 ?>
 </h4>


    <section id="list">
    <?php



    foreach ($usearch as $object) {
    print $object->username;
    }


    ?>

    </div>

  </div>

lastly, here is the var dump when i just call it that way:

    object(stdClass)#2 (2) { ["meta"]=> object(stdClass)#3 (1) { ["code"]=> int(200) } ["data"]=> array(50) { [0]=> object(stdClass)#4 (6) { ["username"]=> string(6) "george" ["bio"]=> string(0) "" ["website"]=> string(0) "" ["profile_picture"]=> string(57) "http://images.ak.instagram.com/profiles/anonymousUser.jpg" ["full_name"]=> string(0) "" ["id"]=> string(7) "7693231" } [1]=> object(stdClass)#5 (6) { ["username"]=> string(9) "instagod7" ["bio"]=> string(28) "Graphic designer 🫠O.D.U." ["website"]=> string(0) "" ["profile_picture"]=> string(76) "http://images.ak.instagram.com/profiles/profile_26017769_75sq_1358524943.jpg" ["full_name"]=> string(6) "George" ["id"]=> string(8) "26017769" } [2]=> object(stdClass)#6 (6) { ["username"]=> string(17) "georgetowncupcake" ["bio"]=> string(81) "Official Instagram account of Georgetown Cupcake | Home of TLC's DC CUPCAKES!" ["website"]=> string(32) "http://www.georgetowncupcake.com" ["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_265095138_75sq_1391136095.jpg" ["full_name"]=> string(18) "Georgetown Cupcake" ["id"]=> string(9) "265095138" } [3]=> object(stdClass)#7 (6) { ["username"]=> string(11) "georgewbush" ["bio"]=> string(79) "43rd President of the United States and Founder of the George W. Bush Institute" ["website"]=> string(21) "http://bushcenter.org" ["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_531790154_75sq_1377896593.jpg" ["full_name"]=> string(14) "George W. Bush" ["id"]=> string(9) "531790154" } [4]=> object(stdClass)#8 (6) { ["username"]=> string(11) "georgelopez" ["bio"]=> string(50) "New Saint George Episode April 10th on @FXNetworks" ["website"]=> string(26) "http://www.georgelopez.com" ["profile_picture"]=> string(76) "http://images.ak.instagram.com/profiles/profile_38811207_75sq_1390655218.jpg" ["full_name"]=> string(12) "George Lopez" ["id"]=> string(8) "38811207" } [5]=> object(stdClass)#9 (6) { ["username"]=> string(14) "georgerauscher" ["bio"]=> string(33) "photography | munich - Impressum:" ["website"]=> string(31) "http://www.george.li/impressum/" ["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_237349510_75sq_1391160241.jpg" ["full_name"]=> string(18) "George A. Rauscher" ["id"]=> string(9) "237349510" }
3
  • Is there a json_decode in there somewhere? Commented Apr 7, 2014 at 21:47
  • What exactly do you want to return as HTML? Each object's property? Commented Apr 7, 2014 at 21:49
  • Object of class stdClass could not be converted to string means that you are trying to echo $object. So you should re-check arrays/objects of your return. Commented Apr 7, 2014 at 21:50

1 Answer 1

3

Presuming the vardump if of the $result variable, the object array you want to iterate is contained within the data property:

foreach ($result->data as $object) {
    print $object->username;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.