Search code examples
javascriptgoogle-apigoogle-oauthgoogle-search-console

How to get access token for Google APIs Data without User Consent using Service Account from Javascript


How to get Access Token for Google APIs without User Consent using Service Account from Javascript or is there other way to get it using API Key, Client Id and Client Secret.


Solution

  • Service accounts can only be used by server sided applications, due to security concerns.

    How to get Access Token for Google APIs without User Consent using JavaScript?

    You cant. If this is private user data then you will need to request consent of the owner to access it.

    If it is public data then you can use an api key to gain read access.

    How can I use a Service Account from JavaScript.

    You cant from Client side javascript, you could switch to Node.js and do it server sided.

    Is there other way to get it using API Key, Client Id and Client Secret.

    An api key will give you access to public data only.

    Is there other way to get it using Client Id and Client Secret.

    Yes you can use Oauth2 to request consent of the user in order to access their data.
    There is no other way with Javascript to gain access to private user data, you must have their consent.