How do I use the PageSpeed Insights API with the Google Python API?
I am currently working on a page api script with a Google Python API client. The API client states that 1000 requests can be completed in a single Batch . However, I am getting 500 errors after 26 requests. Is there any other way to have the limit calculated for PageSpeed Insights?
My current code looks like this:
from apiclient.http import BatchHttpRequest
from apiclient.discovery import build
# URL_LIST = [ 998 lenghthed list of urls ]
def handle_metrics_results(request_id, response, exception):
if exception is not None:
# What say you?
print 'Dude you fail! ' + str(exception)
else:
# Do something with result
print 'Awesome! ' + str(response)
api_key = 'my_api_key'
insights_service = build('pagespeedonline', 'v2', developerKey=api_key)
insights_request_batch = BatchHttpRequest(callback=handle_metrics_results)
for one_url in URL_LIST:
insights_request_batch.add(
insights_service.pagespeedapi().runpagespeed(url=one_url))
insights_request_batch.execute()
Could you point me in the right direction? I really don't know what I am doing wrong here.
+3
source to share
No one has answered this question yet
Check out similar questions: