What is the difference between api key, client id and service account?

I needed to access the Google service, i.e. Google Analytics, from my Symfony 2 application, so I had to use the Google api client (version 2). Before accessing the Google Analytics information, I had to create either an api key, or a client identifier, or a service account in the Google APIs console.

In the end, I created a service account and the file was uploaded. This file is used by the Google api client to provide access to my Google Analytics account and its related information collected.

My question is:

  • What is the difference between api key, client id and service account?

  • When to create / use one above the other and why?

I have not seen an exhaustive article that explains what I am asking in this question.

+8
source share
2 answers

API keys are authenticated for APIs that do not have access to personal data.

The customer ID is authenticated using your Google Account.

The service account authenticates your application if you do not want to use the login information in your account (or any real person account).

You still need to add the service account to any Google service that you want to access with this service account.

+7
source

This topic is old, but still adds information. May help others in the future.

Google needs a unique identifier to associate it with your project (with your Android package) for authentication and for managing traffic or quotas.

Oauth and the API key are such unique identifiers.

OAuth 2.0 client identifiers : if your application uses the OAuth 2.0 protocol, use the OAuth client identifier. OAuth is used to create an access token, which in turn is a unique identifier. However, the user must agree to the consent. https://developers.google.com/identity/protocols/OAuth2

API keys An API key is a unique identifier that you generate using the console. The advantage is that the user does not require user action or consent. But you cannot use the API key for authorization, unlike OAuth. Use the API key when the requested data is public and does not require user authentication, such as Google maps.

Service account : Google APIs, such as the Prediction API and Google Cloud Storage, can act on behalf of your application without access to user information. In these situations, your application must verify its identity with the API, but user consent is not required. Similarly, in enterprise scenarios, your application may request delegated access to certain resources. For these types of interserver interactions, you need a service account. https://developers.google.com/identity/protocols/OAuth2#serviceaccount

+2
source

All Articles