Finding Related Topics using Google Knowledge Graph API

316 views Asked by At

I'm currently working on a behavioral targeting application and I need a considerably large keyword database/tool/provider that enables applications to reach to the similar keywords via given keyword for my app. I've recently found that Freebase, which had been providing a similar service before Google acquired them and then integrated to their Knowledge Graph. I was wondering if it's possible to have a list of related topics/keywords for the given entity.

import json
import urllib

api_key = 'API_KEY_HERE'
query = 'Yoga'
service_url = 'https://kgsearch.googleapis.com/v1/entities:search'
params = {
    'query': query,
    'limit': 10,
    'indent': True,
    'key': api_key,
}
url = service_url + '?' + urllib.urlencode(params)
response = json.loads(urllib.urlopen(url).read())
for element in response['itemListElement']:
  print element['result']['name'] + ' (' + str(element['resultScore']) + ')'

The script above returns the queries below, though I'd like to receive related topics to yoga, such as health, fitness, gym and so on, rather than the things that has the word "Yoga" in their name.

Yoga Sutras of Patanjali (71.245544)
Yōga, Tokyo (28.808222)
Sri Aurobindo (28.727333)
Yoga Vasistha (28.637642)
Yoga Hosers (28.253984)
Yoga Lin (27.524054)
Patanjali (27.061115)
Yoga Journal (26.635073)
Kripalu Center (26.074436)
Yōga Station (25.10318)

I'd really appreciate any suggestions, and I'm also open to using any other API if there is any that I could make use of. Cheers.

1

There are 1 answers

0
Ivan  Filimonov On

See your point:) So here's the script I use for that using Serpstat's API. Here's how it works:

  1. Script collects the keywords from Serpstat's database
  2. Then, collects search suggestions from Serpstat's database
  3. Finally, collects search suggestions from Google's suggestions

Note that to make script work correctly, it's preferable to fill all input boxes. But not all of them are required.

  • Keyword — required keyword
  • Search Engine — a search engine for which the analysis will be carried out. For example, for the US Google, you need to set the g_us. The entire list of available search engines can be found here.

Limit the maximum number of phrases from the organic issue, which will participate in the analysis. You cannot set more than 1000 here.

  • Default keys — list of two-word keywords. You should give each of them some "weight" to receive some kind of result if something goes wrong.

Format: type, keyword, "weight". Every keyword should be written from a new line. Types:

w — one word

p — two words

Examples:

"w; bottle; 50" — initial weight of word bottle is 50.

"p; plastic bottle; 30" — initial weight of phrase plastic bottle is 30.

"w; plastic bottle; 20" — incorrect. You cannot use a two-word phrase for the "w" type.

Bad words — comma-separated list of words you want the script to exclude from the results.

Token — here you need to enter your token for API access. It can be found on your profile page.

You can download the source code for script here