Google drive v2 api示例

时间:2014-09-12 18:16:32

标签: c# google-api google-drive-api

我需要编写示例代码 我需要允许user1 @ gmail.com,user2 @ gmail.com,user3 @ gmail.com,...使用sdk访问google云端硬盘帐户中的所有文件( my_mail@gmail.com ) 。 我试过这个(在google开发者控制台上安装应用程序),该服务返回当前时间在浏览器中登录的用户文件

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);

我在asp.net mvc上写道,希望你是肝脏

1 个答案:

答案 0 :(得分:0)

您的应用需要存储my_mail@gmail.com的刷新令牌,然后使用它来生成访问令牌。您可以使用How do I authorise an app (web or installed) without user intervention? (canonical ?)中的步骤,这意味着您无需编写任何授权码。