Javascript 谷歌自定义搜索承诺尚未完成
我正在尝试用它学习NodeJs和javascript。我尝试了以下代码片段。我使用了来自的请求格式 我还尝试使用promise,如下所示:Javascript 谷歌自定义搜索承诺尚未完成,javascript,node.js,google-api,promise,webpack,Javascript,Node.js,Google Api,Promise,Webpack,我正在尝试用它学习NodeJs和javascript。我尝试了以下代码片段。我使用了来自的请求格式 我还尝试使用promise,如下所示: client.search('Steve Angello') .then(function(result) { console.log("Result was fetched") }) .catch(function(error) { console.error("Error: " + error); });
client.search('Steve Angello')
.then(function(result) {
console.log("Result was fetched")
})
.catch(function(error) {
console.error("Error: " + error);
});
我可以看到控制台执行开始和执行完成时的输出,但看不到是否有错误或是否提取了结果。我能够在网络调用中看到google Api返回Json格式的结果,如下所示:
"searchInformation": {
"searchTime": 0.16809,
"formattedSearchTime": "0.17",
"totalResults": "4580000",
"formattedTotalResults": "4,580,000"
},
"items": [
{
"kind": "customsearch#result",
"title": "Steve Angello : Omnia",
"htmlTitle": "\u003cb\u003eSteve Angello\u003c/b\u003e : Omnia",
"link": "http://s3-us-west-1.amazonaws.com/staging.omnianightclub.com/uploads/2015/05/150000_OMLV_HomepageDiamond_669x1000_SteveAngello.png",
"displayLink": "omnianightclub.com",
"snippet": "Steve Angello : Omnia",
"htmlSnippet": "\u003cb\u003eSteve Angello\u003c/b\u003e : Omnia",
"mime": "image/png",
"fileFormat": "Image Document",
"image": {
"contextLink": "http://omnianightclub.com/artist/steve-angello/",
"height": 1000,
"width": 669,
"byteSize": 403470,
"thumbnailLink": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQ56da5kw1I8l13Z8cL2reLUgS4FU1_rc6ZcW0r72GWc02gCCeMsogEwcmu",
"thumbnailHeight": 149,
"thumbnailWidth": 100
}
},
{
"kind": "customsearch#result",
"title": "steve angello Archives | We Rave You",
"htmlTitle": "\u003cb\u003esteve angello\u003c/b\u003e Archives | We Rave You",
"link": "http://weraveyou.com/wp-content/uploads/2016/05/steve-angello.jpg",
"displayLink": "weraveyou.com",
"snippet": "Steve Angello compiles a firey ...",
"htmlSnippet": "\u003cb\u003eSteve Angello\u003c/b\u003e compiles a firey ...",
"mime": "image/jpeg",
"image": {
"contextLink": "http://weraveyou.com/tag/steve-angello/",
"height": 1365,
"width": 2048,
"byteSize": 213185,
"thumbnailLink": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSwTxjcVJ87o9suz6e7K7iRW4XtJpebnTanPOGxseRypkQDOaEJezqagfs",
"thumbnailHeight": 100,
"thumbnailWidth": 150
}
}
PS:我正在使用webpack devserver,这可能是一个原因吗?什么是
,这是)代码>,在最后第三行?我使用了@PhatomM的请求格式,但您使用的是google images npm包,不是吗?是的,我也尝试过这样做。客户端搜索('Steve Angello')。然后(函数(内容){console.log(“获取内容”)})。catch(函数(错误){console.error(“错误:”;});什么是},这个)代码>,在最后第三行?我使用了@PhatomM的请求格式,但您使用的是google images npm包,不是吗?是的,我也尝试过这样做。客户端搜索('Steve Angello')。然后(函数(内容){console.log(“获取内容”)})。catch(函数(错误){console.error(“错误:”;});
"searchInformation": {
"searchTime": 0.16809,
"formattedSearchTime": "0.17",
"totalResults": "4580000",
"formattedTotalResults": "4,580,000"
},
"items": [
{
"kind": "customsearch#result",
"title": "Steve Angello : Omnia",
"htmlTitle": "\u003cb\u003eSteve Angello\u003c/b\u003e : Omnia",
"link": "http://s3-us-west-1.amazonaws.com/staging.omnianightclub.com/uploads/2015/05/150000_OMLV_HomepageDiamond_669x1000_SteveAngello.png",
"displayLink": "omnianightclub.com",
"snippet": "Steve Angello : Omnia",
"htmlSnippet": "\u003cb\u003eSteve Angello\u003c/b\u003e : Omnia",
"mime": "image/png",
"fileFormat": "Image Document",
"image": {
"contextLink": "http://omnianightclub.com/artist/steve-angello/",
"height": 1000,
"width": 669,
"byteSize": 403470,
"thumbnailLink": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQ56da5kw1I8l13Z8cL2reLUgS4FU1_rc6ZcW0r72GWc02gCCeMsogEwcmu",
"thumbnailHeight": 149,
"thumbnailWidth": 100
}
},
{
"kind": "customsearch#result",
"title": "steve angello Archives | We Rave You",
"htmlTitle": "\u003cb\u003esteve angello\u003c/b\u003e Archives | We Rave You",
"link": "http://weraveyou.com/wp-content/uploads/2016/05/steve-angello.jpg",
"displayLink": "weraveyou.com",
"snippet": "Steve Angello compiles a firey ...",
"htmlSnippet": "\u003cb\u003eSteve Angello\u003c/b\u003e compiles a firey ...",
"mime": "image/jpeg",
"image": {
"contextLink": "http://weraveyou.com/tag/steve-angello/",
"height": 1365,
"width": 2048,
"byteSize": 213185,
"thumbnailLink": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSwTxjcVJ87o9suz6e7K7iRW4XtJpebnTanPOGxseRypkQDOaEJezqagfs",
"thumbnailHeight": 100,
"thumbnailWidth": 150
}
}