0

I need to write sample code I need to allow [email protected], [email protected], [email protected],... access to all my files([email protected]) in google drive account using sdk. I tried this(install application on google developers console), and the service returns the files of user which login in browser in current time

ClientSecrets secrets = new ClientSecrets
{
    ClientId = CLIENT_ID,
    ClientSecret = CLIENT_SECRET,
};

IDataStore StoredRefreshToken = new SavedDataStore(new StoredResponse() { });
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(secrets,
        SCOPES, "1", CancellationToken.None, StoredRefreshToken /*, credentialPersistanceStore*/).Result;

BaseClientService.Initializer initializer = new BaseClientService.Initializer
{
    HttpClientInitializer = credential,
    ApplicationName = APP_USER_AGENT
};

return new DriveService(initializer);

I write on asp.net mvc, hope you are hepls

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194

1 Answers1

0

Your app needs to store a refresh token for [email protected] and then use that to generate an access token. You can use the steps at How do I authorise an app (web or installed) without user intervention? (canonical ?) which means you don't need to write any authorisation code.

Community
  • 1
  • 1
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • ClientSecrets secrets = new ClientSecrets {ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET, };IDataStore StoredRefreshToken = new SavedDataStore(new StoredResponse() { }); UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, SCOPES, "1", CancellationToken.None, StoredRefreshToken /*, credentialPersistanceStore*/).Result; BaseClientService.Initializer initializer = new BaseClientService.Initializer {HttpClientInitializer = credential, ApplicationName = APP_USER_AGENT };var service = DriveService(initializer); – user3220643 Sep 13 '14 at 06:41
  • FileList files = service.Files.List().Execute();return files.Items.Count; and this return the count files in current logged user in browser, and i need a only my files without loggin in account in browser – user3220643 Sep 13 '14 at 06:45
  • All of the Google sample code is for a conventional user authorising access to how own resources. You can't copy paste it as your use case is different. You will need to research the Google OAuth SDK to figure out how to get it to use your stored refresh token. Or stop using it and simple call the OAuth the endpoint yourself. It's described here https://developers.google.com/accounts/docs/OAuth2WebServer#refresh – pinoyyid Sep 13 '14 at 07:07