2015-11-25 53 views
1

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

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

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

感谢,

回答

2

这将是一个很长的答案,我从我的教程大多是复制文本Google .net – FileDatastore demystified

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

因此,我们将有一个名为%AppDatat%\ Drive.Auth.Store的新目录。当我检查我的机器,我觉得在这里C:\用户\ lindaHP \应用程序数据\漫游\ Drive.Auth.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; 
     } 

假设用户点击接受认证请求屏幕上,一个新的文件将被创建该目录结构如下:

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

答:

Userid是你想要它只是一个字符串。它只是用来区分同一台计算机上的多个用户保存身份验证。

当您想要再次加载用户时,您将传递该用户的用户标识,客户端库将加载他或她的认证。这在windows phone上并不是非常需要。应该可能只有一个用户。

如果你想加载不同的用户,你可以改变用户ID,它将保存该用户的认证(或者如果有问题的用户已经认证你的应用,则加载它)