0

I'm trying to explore the uspto programmatically using the google custom search API. As a first step and sanity, I tried to run an existing script, Posted here at Stack Overflow with a small change (urllib.quote became urllib.parse.quote). Here's the code:

import requests
import urllib
import time
import json

access_token = <get yours by signing up for google custom search engine api>
cse_id = <get yours by signing up for google custom search engine api>

# Build url
start=1
search_text = "+(inassignee:\"Altera\" | \"Owner name: Altera\") site:www.google.com/patents/"
# &tbm=pts sets you on the patent search
url = 'https://www.googleapis.com/customsearch/v1?key='+access_token+'&cx='+cse_id+'&start='+str(start)+'&num=10&tbm=pts&q='+ urllib.parse.quote(search_text)

response = requests.get(url)

response.json()
f = open('Sample_patent_data'+str(int(time.time()))+'.txt', 'w')
f.write(json.dumps(response.json(), indent=4))
f.close()

Here's what I got in the response file:

{
    "error": {
        "errors": [
            {
                "domain": "usageLimits",
                "reason": "keyInvalid",
                "message": "Bad Request"
            }
        ],
        "code": 400,
        "message": "Bad Request"
    }
}

What's wrong with the search? It's not an authentication error, so what's wrong? Thanks everyone and have a nice day (-:!

Julius
  • 41
  • 5

2 Answers2

0

I think there is something wrong with your API key. You can find a similar question at Google Custom Search Api keeps giving me "usageLimits" error. You could try requesting a new key.

After that, do you definitely have to use google custom search API? If you plan to make a small number of requests, consider using https://pypi.org/project/google-search/.

Hope it helps.

curi0uz_k0d3r
  • 505
  • 2
  • 9
0

If you want use just google patent for your search you can configure it from custom search set up and add it as Sites to search option. Remove site:www.google.com/patents/ from search_text and it should work.