.net 用OAuthaAuthenticator替换OAuthUri

.net 用OAuthaAuthenticator替换OAuthUri,.net,google-oauth,.net,Google Oauth,我的意见如下: Uri retUri = null; if (this.settings.OAuthUser != null && location.IndexOf(OAuthUri.OAuthParameter) != 0) { // // How to replace in the following line // the OAuthUri with OAuthAuthenticator ? // retUri = n

我的意见如下:

Uri retUri = null; 

if (this.settings.OAuthUser != null && 
    location.IndexOf(OAuthUri.OAuthParameter) != 0)
{
    //
    // How to replace in the following line 
    // the OAuthUri with OAuthAuthenticator ?
    //
    retUri = new OAuthUri(location, this.settings.OAuthUser, 
                          this.settings.OAuthDomain);
}
else 
{
    retUri = new Uri(location);
}
警告说:

警告196“Google.GData.Client.OAuthUri”已过时:“这将继续。” 将来将被删除并替换为OAuthAuthenticator'


我认为您使用的是旧版本的Google客户端库

PM> Install-Package Google.Apis
Oauth代码如下所示

UserCredential credential; 
 credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
              new ClientSecrets { ClientId = "YourClientId", ClientSecret = "YourClientSecret" },
              new[] { DriveService.Scope.Drive,
                DriveService.Scope.DriveFile },
              "user",
              CancellationToken.None,
              new FileDataStore("Drive.Auth.Store")).Result; }
作用域将根据您尝试连接到的API而变化。另外,FileDatastore将刷新令牌存储在%AppData%中,如果要将其存储在其他地方,则需要自行实现Idatastore

这里有一个简短的教程