用于.NET的Google API-idadastore用户ID

本文关键字:用户 ID API-idadastore Google NET 用于 | 更新日期: 2023-09-27 18:24:28

我是Google API的新手,尝试在Windows Phone上使用其.NET客户端库。

我正在使用GoogleWebAuthorizationBroker来授权用户。问题是它有一个"userID"参数。它是什么?是谷歌电子邮件帐户吗?我如何在应用程序第一次运行时知道用户的帐户?

https://developers.google.com/api-client-library/dotnet/reference/1.9.2/classGoogle_1_1Apis_1_1Auth_1_1OAuth2_1_1GoogleWebAuthorizationBroker#a95045cb55eeb08fadd27b33e0193327c

谢谢,

用于.NET的Google API-idadastore用户ID

这将是一个很长的答案,我主要从我的教程Google.net–FileDatastore解密中复制文本

让我们看看FileDataStore。当以下代码进行身份验证时。将在执行代码的计算机上的%AppData%目录中创建名为Drive.Auth.Store的文件夹。

因此,我们将有一个名为%AppDatat%''Drive.Auth.Store的新目录。当我检查我的机器时,我会在这里找到它C:''Users''lindaHP''AppData''Roaming''Drive.AAuth.Store

UserCredential credential;
using (var stream = new FileStream(clientSecretsJsonFilePath
                                   ,FileMode.Open
                                   ,FileAccess.Read))
      {   
      credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
      GoogleClientSecrets.Load(stream).Secrets,
      new[] { DriveService.Scope.Drive,  DriveService.Scope.DriveFile },
      "LookIAmAUniqueUser",
       CancellationToken.None,
      new FileDataStore("Drive.Auth.Store")                               
      ).Result;
      }

假设用户在身份验证请求屏幕上单击accept,将在该目录中创建一个具有以下结构的新文件:

Google.Apis.Auth.OAuth2.Responses.TokenResponse-LookIAmAUniqueUser.TokenResponse_LookIAmAUniqueUser

答案:

Userid是你想要的,它只是一个字符串。它只是用来区分同一台机器上的多个用户,从而节省身份验证。

当您想再次加载用户时,您可以传递该用户的userid,客户端库将加载他或她的身份验证。这在windows phone上并不是真正需要的。可能只有一个用户。

如果你想加载一个不同的用户,你可以更改userid,它将保存该用户的身份验证(或者如果有问题的用户已经验证了你的应用程序,则加载它)