2014-04-04 53 views
1

我有如下因素:更換OAuthUri與OAuthAuthenticator

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'

回答

0

我認爲您使用的是舊版本的Google客戶端lib

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。

這裏有一個簡短的教程Google Oauth2 C#