简体   繁体   中英

Google feed api not returning results with php in wordpress

i am trying to use the google feed api in my wordpress site. i have enabled php with a plugin, which allows me to input php code in my pages. my hosting provider also confirmed they have curl enabled.

This is the code which iam trying to run which i got from the google developer site ( https://developers.google.com/feed/v1/jsondevguide#basic_query )

<?php 
$url = "https://ajax.googleapis.com/ajax/services/feed/find?v=1.0&q=iphone5&  userip=2.96.214.41";

// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, http://www.iweb21.com);
$body = curl_exec($ch);
curl_close($ch);

// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...
?>

i don't get any results, just a blank page.

i am not a php programmer. just a novice wordpress user. i have been searching for a plugin to use the google feed api but got nowhere. so i decided to try using the code provided by google.

i Would very much appreciate any advise. thnx

Blank page means that there is a Fatal or Parse error, and error reporting is disabled in PHP settings. See this: How to get useful error messages in PHP?

In your particular case, the referer string is not enclosed in quotes and generates a Parse Error. Replace with:

curl_setopt($ch, CURLOPT_REFERER, 'http://www.iweb21.com');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM