使用谷歌API域索引检查 [英] Domain index checking using Google API

查看:117
本文介绍了使用谷歌API域索引检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立网站,用户可以输入自己的网站,并检查他在谷歌索引。
就像我们通过网​​站做的事:domain.com

I am trying to build website where a user can enter his website and check his indexed pages in google. Just like we do by site:domain.com

我使用谷歌的API,这里是链接到API(我知道这是德precated)

I am using a google API, here is the link to API (I know it's deprecated)

http://ajax.googleapis.com/ AJAX /服务/搜索/ WEB v = 1.0安培; q =

当我使用code像

<?php  

function getGoogleCount($domain) {
    $content = file_get_contents('http://ajax.googleapis.com/ajax/services/' .
        'search/web?v=1.0&filter=0&q=site:' . urlencode($domain));
    $data = json_decode($content);
    return ($data->responseData->cursor->estimatedResultCount);
}

echo getGoogleCount('stackoverflow.com');

?>

据我想好了解的结果数量
但我想,接下来的事情是列出所有我的网站上的结果。我不能抢的结果,因为当我们写

good as far as I want to know about the result counts But the next thing I want is to list all the results on my website. I am unable to grab the results because when we write

$data->responseData->cursor->estimatedResultCount

它直接
但是,当我们试图得到结果。我不知道该怎么做,只是为了打印想法

It goes straight But when we try to get results. I don't know how to do, just to print the idea

$data->responseData->results->[url & title & content here]

由于这里的结果是一个数组。我不知道我怎么可以存储信息,在这种情况下,一个数组。

Because here results is an array. and I don't know how can I store info in an array in this case.

一直在寻找了很久却找不到任何相关.....

Have been searching for a long time but can't find anything related.....

在此先感谢...

推荐答案

最简单的方法是使用:

$data = json_decode($content, true);

这将对象转换为正常的关联数组这可能就好办了。
然后,你的东西访问你的价值观是这样的:

That will convert objects to normal associative arrays which are probably easier to handle. Then you access your values by something like this:

$results = $data['responseData']['results']; //array
$googleCount = $data['responseData']['cursor']['estimatedResultCount'];

然后的结果,你可以做这样的事情:

Then with the results you can do something like this:

foreach ($results as $result) {
    echo $result['title'].' -> '.$result['url'] . '<br />';
}

不过,当然,如果你不喜欢关联数组和你preFER对象,你可以做到这一点也是这样说的:

But of course if you don't like associative arrays and you prefer objects, you could do it also this way:

$data = json_decode($content);
foreach ($data->responseData->results as $result) {
    echo $result->title .' -> '.$result->url.'<br />';
}

如果您要检查的属性有$结果,只要使用的print_r 的var_dump

If you want to check which properties has the $result, just use print_r or var_dump.

这篇关于使用谷歌API域索引检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆