我正在尝试在我的 ASP 程序中获取 Google Drive 的授权代码。我从 Google API for .NET 示例中编写了一些代码,例如快速启动程序:
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg){
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(
new[] {DriveService.Scopes.Drive.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
//Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
我想通过打开一个弹出窗口来获取授权码,用户可以在此访问权限,在用户访问权限后,这将返回代码。