1

hI, I could not get this right. I would like to get the totalResults from this returned json result
full text: http://code.google.com/apis/customsearch/v1/using_rest.html

 "request": [ { "title": "Google Custom Search - flowers", "totalResults": 10300000, "searchTerms": "flowers", } ] }, 

i tried this:

$response = file_get_contents('https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=013036536707430787589:_pqjad5hr1a&q=flowers&alt=json '); $json = json_decode($response); echo "Total Result:".$json->request->totalResults; 

but i got nothing. Need help pls. Thanks.

2
  • Did you insert your key where it says INSERT-YOUR-KEY? Commented Feb 20, 2011 at 16:32
  • yes I did insert the api key. just dont know how to display only the totalResults; Commented Feb 20, 2011 at 16:32

2 Answers 2

1

In your post it's not visible all the json. In my tests it works with this:

$json->queries->request[0]->totalResults;

Sign up to request clarification or add additional context in comments.

Comments

0

Perhaps try an if(!is_null($json->request->totalResults)) conditional to see if you're even getting a response.

3 Comments

I am getting a response and the response structure pattern is in json and similar to this url ; code.google.com/apis/customsearch/v1/using_rest.html code$json->request->totalResultscode doesnt seem to work.
I grabbed the JSON from the Google page you linked to and this worked for me: code$json->queries->request[0]->totalResults
ok.. thanks. now I know how to get it.. Thanks a lot @jondbaker

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.