java google custom search api [英] java google custom search api

查看:205
本文介绍了java google custom search api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 java Google自定义搜索API的客户端
但无法在网络上找到任何示例教程。有人能为我提供一个简单的例子吗?谢谢!

I'm trying to use the java client for the Google custom search api but couldn't find any sample tutorials on the web. Can someone provide a simple example for me to get started? Thank you!

推荐答案

我想在这里进行修正。

customsearch.setKey("YOUR_API_KEY_GOES_HERE");

不适用于客户端lib 1.6但后续工作

does not work for client lib 1.6 but following does work

     Customsearch customsearch = new Customsearch(new NetHttpTransport(), new JacksonFactory());

    try {
        com.google.api.services.customsearch.Customsearch.Cse.List list = customsearch.cse().list("YOUR_SEARCH_STRING_GOES_HERE");
        list.setKey("YOUR_API_KEY_GOES_HERE");
        list.setCx("YOUR_CUSTOM_SEARCH_ENGINE_ID_GOES_HERE");
        Search results = list.execute();
        List<Result> items = results.getItems();

        for(Result result:items)
        {
            System.out.println("Title:"+result.getHtmlTitle());

        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

这篇关于java google custom search api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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