Google Web授权经纪人创建秘密uri

Noz*_*rum 4 c# google-authentication google-drive-api

我想为我的程序创建UserCredentials,这个任务的签名似乎是

Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(
(Uri clientSecretsUri, IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken);
Run Code Online (Sandbox Code Playgroud)

我发现的所有教程只是创建一个ClientSecrets类并将其作为参数传递,遗憾的是这个类没有.ToUri()方法.我也找不到关于如何构建这个uri的任何文档.因此,鉴于我明显拥有我的客户端ID和秘密(如果需要,还可以重定向uri),如何创建此授权所需的uri?

Mar*_*ter 7

我假设您正在为通用Windows平台开发?然后这将工作:

正如neosapien所说,您可以从Developer Console下载client_secrets.json .

使用构建操作将其添加到项目中Content.

然后根据你在项目中的位置(在这种情况下<ProjectDirectory>/Assets/client_secrets.json)加载它,如下所示:

await GoogleWebAuthorizationBroker.AuthorizeAsync( 
                    new Uri("ms-appx:///Assets/client_secrets.json"),
                    new[] {CalendarService.Scope.Calendar, DriveService.Scope.Drive},
                    "user",
                    CancellationToken.None)
Run Code Online (Sandbox Code Playgroud)