Introduction
This document is intended for developers who want to write applications that can interact with the PageSpeed Insights API.
PageSpeed Insights is a tool that helps developers optimize their web pages by analyzing the pages and generating tailored suggestions to make the pages faster. You can use the PageSpeed Insights API to programmatically generate PageSpeed scores and suggestions.
Before you start
Get a Google Account
You need to have a Google Account so you can get an API key to identify your application to Google. (See below.)
Get familiar with PageSpeed
If you're unfamiliar with PageSpeed, see the PageSpeed Web Performance Best Practices.
Learn how to identify your application to Google
Your application needs to identify itself every time it sends a request to the PageSpeed Insights API, by including an API key with each request.
Acquiring and using an API key
To acquire an API key:
- Open the Credentials page.
- This API supports two types of credentials. Create whichever credentials are appropriate for your project:
- OAuth: Your application must send an OAuth 2.0 token with any request that accesses private user data. Your application sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.To create an OAuth 2.0 token, click Create new Client ID, provide the required information where requested, and click Create Client ID.You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.
Web applications
A web application is accessed by web browsers over a network.- Applications that use JavaScript to access the PageSpeed Insights API must specify authorized JavaScript origins. The origins identify the domains from which your application can send API requests.
- Applications that use languages and frameworks like PHP, Java, Python, Ruby, and .NET must specify authorized redirect URIs. The redirect URIs are the endpoints to which the OAuth 2.0 server can send responses.
Service accounts
A service account is used in an application that calls APIs on behalf of an application that does not access user information. This type of application needs to prove its own identity, but it does not need a user to authorize requests. The Google Accounts documentation contains more details about service accounts.