当前位置: 动力学知识库 > 问答 > 编程问答 >

php - how to get json response from google custom search Api

问题描述:

Actually i want to search question from google and its answer

for example

question

what is definition of astrology.

answer

the study of the movements and relative positions of celestial bodies interpreted as having an influence on human affairs and the natural world.

like that i want from this api

how it is possible

 $search_query = $this->input->post('search');

$url ="https://www.googleapis.com/customsearch/v1?key=AIzaSyD7Ho22AiuqaieQmg1GyMP9HxvID0V0VWg&cx=003432080158696714251:n4rbif5gizk&q='$search_query'";

网友答案:

Here is a sample code.

$json = file_get_contents($url);

$results = json_decode($json);

if ($results->searchInformation->totalResults) {
    $resutItems = $results->items;
    // do whatever with the result
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: