Simple Node.js module for Google Graph Knowledge API.
Returns all possible types to build search parameters.
constKnowledge=require('knowledge-node')({serverKey: '<Your Google Server Key>'});constallTypes=Knowledge.types;console.log(allTypes);//"types": {// "book": "Book",// "bookSeries": "BookSeries",// "educationalOrganization": "EducationalOrganization",// ...//}Builds parameter object to be used on search request.
| Parameter | Type | Required | Information |
|---|---|---|---|
| query | String | Yes | |
| limit | Number | No | Default: 20 |
| indent | Boolean | No | Defaut: true |
| types | Array[Types] | Yes |
constKnowledge=require('knowledge-node')({serverKey: '<Your Google Server Key>'});constquery='Harry Potter';consttypes=[Knowledge.types.book,Knowledge.types.bookSeries];constlimit=5;constindent=true;constparameters=Knowledge.buildParams(query,types,limit,indent);//{// "query": "Harry Potter",// "limit": 5,// "indent": true, // "key": "<Google API Key>",// "types": [// "Book",// "BookSeries"// ]//}Makes search request to Google Knowledge API.
You must define correctly the search parameters: please read Build Parameters section.
For more extensive information about errors and successful body response, please read Google Knowledge Graph API Documentation.
constKnowledge=require('knowledge-node')({serverKey: '<Your Google Server Key>'});constquery='Harry Potter';consttypes=[Knowledge.types.book,Knowledge.types.bookSeries];constparams=Knowledge.buildParams(query,types);returnKnowledge.search(params).then(body=>{//do something with success response}).catch(error=>{//handle error});First you should follow the Google Knowledge Graph Search API Prerequisites, so you have your Google Account setup.
Edit ./test/fixtures/auth.json file and add your Google Server Key. Install the dev dependencies and run the tests:
$ npm install
$ npm test
Licensed under the MIT License.