【发布时间】:2015-11-21 01:13:05
【问题描述】:
我想为工作表和谷歌驱动器 api 使用 相同的 OAuth 代码和令牌,而不需要为工作表和驱动器重定向到第 2 页。
以下是使用 oauth 2 生成访问码和令牌的代码
string SCOPE = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds";
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.ClientId = CLIENT_ID;
parameters.ClientSecret = CLIENT_SECRET;
parameters.RedirectUri = REDIRECT_URI;
parameters.Scope = SCOPE;
string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
OAuthUtil.GetAccessToken(parameters);
string accessToken = parameters.AccessToken;
与 asp.net mvc 一样,它是通过 google sheet API 的重定向生成的。
我也想将 google drive API 用于相同的令牌。
我如何为 google Drive API 创建凭据对象以便使用它。跟随代码打开另一个窗口并将代码发送到该窗口。
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
ClientId = clientId,
ClientSecret = clientSecret
}, scopes, "skhan", CancellationToken.None, new FileDataStore("Drive.Auth.Store")).Result;
【问题讨论】:
标签: c# asp.net-mvc oauth google-drive-api google-api-dotnet-client