Question: In my solution I need to get messages from gmail.
But everytime, when I do it, I see on my local machine this message 
[![enter image description here](https://i.stack.imgur.com/C7Ur1.jpg)](https://i.stack.imgur.com/C7Ur1.jpg)

Sure, if I confirm it, I get needed data, but this approach doesn't fit me well, especially, when I am going to put it on a daily run.
Does anybody know, how can I avoid of this confirmation window?
Thanks a lot.

Answer: 
You need to ask for permission for offline access. From their documentation:

> 
> If your application requires offline access, the first time your app exchanges the authorization code, it also receives a refresh token that it uses to receive a new access token after a previous token has expired. Your application stores this refresh token (generally in a database on your server) for later use.
> 
> 
> 

Unfortunately, they don't provide enough examples of how to do that. 

The first thing you need to do is add 'offline' to your scope when making the request for obtaining the login url. Doing so will result with getting a refresh token in the API's response. Save that token in the database and any time you need to access the account, you will be able to refresh the token and get an access token without requesting an authorization from the user.

In PHP, using their SDK, the refresh can be done as easy as 

`$this->client->refreshToken($refreshToken)` 

(where client is an instance of their Client class). Should be similar in all other SDKs they provide. Check the functions in the class you're using.
Try to use [Service Accounts](https://developers.google.com/api-client-library/dotnet/get_started#service-accounts) instead.

> 
> 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.
> 
> 
> 

[Setting up service account](https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount):

> 
> 1. Open the Service accounts section of the Developers Console's Permissions page.
> 2. Click Create service account. In the Create service account window, type a name for the service account and select Furnish a new private
>  key.
> 3. If you want to grant Google Apps domain-wide authority to the service account, also select Enable Google Apps Domain-wide
>  Delegation. Then, click Create. Your new public/private key pair is
>  generated and downloaded to your machine; it serves as the only copy
>  of this key. You are responsible for storing it securely.
> 
> 
> You can return to the Developers Console at any time to view the email
>  address, public key fingerprints, and other information, or to
>  generate additional public/private key pairs. For more details about
>  service account credentials in the Developers Console, see Service
>  accounts in the Developers Console help file.
> 
> 
> Take note of the service account's email address and store the service
>  account's P12 private key file in a location accessible to your
>  application. Your application needs them to make authorized API calls.
> 
> 
>