Reputation: 805
I have this problem about google drive. This is my application
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
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
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
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
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