3
votes

i have online tool that works with users based on oauth 2.0. I have access to their Google Analytics, etc.

The only one that i can't access is PageSpeed API because i don't know and can't find scope URL of this service.

For Google Analytics, for example, i use https://www.googleapis.com/auth/analytics.readonly scope etc. But it seems like PageSpeed api does'nt have any scope and is accessible only with user API key. But in that case i can't offer to my users Pagespeed insights for their pages (because one API key has only 50 000 queries/day).

I did'nt find even in Oauth playground on: https://developers.google.com/oauthplayground/

Can you please help me how to solve this problem if i don't wanna press users to Google Developer Console?

Thank you!

2

2 Answers

1
votes

PageSpeed API access works fine with just an API key (as mentioned in the Google Developers Console, see the subpage there for the PageSpeed API) which is also much easier to implement for the developer.

I think this is the case because one can by default run pagespeed for any given URL, so no need for a permission workflow as opposed to Google Analytics etc.

1
votes

As answered above, it should work just fine with an api call. As per the Google PageSpeed Insights API.

This is your API URL for v2 of the API: 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?'

The current version however is, v4. So that looks like this: https://www.googleapis.com/pagespeedonline/v4/runPagespeed

Here's a sample function to call Pagespeed API, using v2:

def runPageSpeed(API_URL, API_KEY, input_url, insightstrategy):
  query = [
    'url=' + input_url,'filter_third_party_resources=true',
    'key='+api_key, 'strategy='+insightstrategy] #insight strategy is either 'desktop' or 'mobile'
  src = API_URL + '&'.join(query)
  return src

P.S: you will need API Key, which you can generated under Google Developers, in order to run it. Also the following packages: (as per I checked last):

  1. google python api client
  2. requests

Try this and And you should be good. No need for oauth.