3

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

3 Answers 3

4
+25

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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/

Comments

2

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.

1 Comment

ahm i check the source code and run it. although the allow request is gone. It still opens up a browser to get the token..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.