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 (-:!