last day (15 days later) » 

3:49 PM
1
A: How to echo the cURL result in PHP?

brandelizerMaybe like this: <?php $url = "https://ajax.googleapis.com/ajax/services/search/images?" . "v=1.0&q=barack%20obama&userip=INSERT-USER-IP"; // sendRequest // note how referer is set manually $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT...

 
Fatal error: Cannot use object of type stdClass as array on line ... this is what I get after using your code ;)
 
Why -1? i dont know what the api gives you back.
 
You would if you would actually access the URL that the OP provided ;)
just for future reference: {"responseData": {"results":[{"GsearchResultClass":"GimageSearch","width":"608","height":"766"..‌​‌​.
now, after your edit, I get a blank response... DO YOU EVEN TEST YOUR CODE?
it should be $pic->results[0]->unescapedUrl OR 2 foreaches OR one foreach but different that what you provided
 
No i have not tested it, but i work a lot with curl and jsons... Sorry but the ky was the foreach and if he gets an object he only has to access the unescaped url i think
now it should do the work...
 
Much better :) sorry to be such a pain but I really like PHP when it's done right :)
 
3:49 PM
I think you two are both excellent. But I still have problem now. I hope you can help me solve it together.
 
you have +1 from me for that catch ;)
 
I tried the edited code. But it still has something wrong. "Trying to get property of non-object" and "Invalid argument supplied for foreach()"
 
OK man. please post an error_log(var_export($pics,true));
 
Thanks for your patience~ I am not good at coding, but I try to do my best. > <
By the way, I use Wampserver. I don't know what to type in "/* Enter the URL of your site here */", and my ip is dynamic.
 
Ohhhh... that is the problem. Do you have a registered Domain?
You have to tipe in "example.com&quot; or something similar
 
3:49 PM
okay~ I'll try and then reply the result for you.
I still don't how to do. Does it have another way? My target is use it to search images from google and then get the picture link.
 
 
2 hours later…
5:59 PM
I would like to know whether it has another way to save the result of "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=snoopy" without user ip.
in my php code, I want to echo $body the most instead of picture link now.
@brandelizer do you know any method can make it come true? (without user ip and registered domain)
 

  last day (15 days later) »