thenewbie
thenewbie

Reputation: 805

How to authenticate once in google drive api

I have this problem about google drive. This is my application enter image description here

As you can see here. I want to browse and upload the file to google drive. But every time I upload a file i need to allow and copy the authentication to my application.. like here

enter image description here

Is it possible to allow access once? Is there any other way to fix this? Can i automatically allow access to the authentication code within my application so that i may not use the browser??

Upvotes: 3

Views: 2201

Answers (3)

Ali Afshar
Ali Afshar

Reputation: 41663

You need to request is "offline" access. This will give you a refresh token that you can use to get a fresh access token forever, or until the user revokes it.

See https://developers.google.com/drive/credentials for a .NET example.

Upvotes: 4

prthrokz
prthrokz

Reputation: 1150

Please have a look at Authorizing with stored credentials within Authorization for Google Drive. Basically you can access the account as long as the stored access_token does not expire.

Upvotes: 2

user1936704
user1936704

Reputation:

if you are running server app how about using OAuth2? You won't need to use users console.

GoogleCredentials credentials = new GoogleCredential.Builder()
     .setTransport(HTTP_TRANSPORT)
     .setJsonFactory(JSON_FACTORY)
     .setServiceAccountId("[[SERVICE_ACCOUNT_EMAIL]]")
     .setServiceAccountScopes(DriveScopes.DRIVE, DriveScopes.DRIVE_FILE,
         "https://www.googleapis.com/auth/userinfo.email",
         "https://www.googleapis.com/auth/userinfo.profile")
     .setServiceAccountPrivateKeyFromP12File(Auth.keyFile)
     .setServiceAccountUser("[[impersonateduser@domain]]")
     .build();
credentials.refreshToken();

and I've found this blog about OAuth2:

http://blog.databigbang.com/automated-browserless-oauth-authentication-for-twitter/

Upvotes: 4

Related Questions