Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ASP.net/C中使用刷新令牌、ClientId和ClientSecret获取Google Drive API的UserCredential#_C#_Asp.net_Google Drive Api_Google Oauth_Google Api Dotnet Client - Fatal编程技术网

C# 在ASP.net/C中使用刷新令牌、ClientId和ClientSecret获取Google Drive API的UserCredential#

C# 在ASP.net/C中使用刷新令牌、ClientId和ClientSecret获取Google Drive API的UserCredential#,c#,asp.net,google-drive-api,google-oauth,google-api-dotnet-client,C#,Asp.net,Google Drive Api,Google Oauth,Google Api Dotnet Client,我可以按照此链接中给出的说明获取RefreshToken: 现在我需要用户凭据来获取driveservice对象。我找了很多,但找不到确切的答案 我可以使用刷新令牌、ClientId和ClientSecret通过以下链接获取访问令牌: 但在那之后,我如何使用该AccessToken获取用户凭证?或使用刷新令牌获取凭证的任何直接方式。任何例子或建议 谢谢 您可能想尝试使用客户机库来处理这个而不是那个。您只需运行以下代码一次。刷新令牌将由FileDataStore创建,并存储在%appData%目录

我可以按照此链接中给出的说明获取RefreshToken:

现在我需要
用户凭据
来获取driveservice
对象
。我找了很多,但找不到确切的答案

我可以使用刷新令牌、
ClientId
ClientSecret
通过以下链接获取访问令牌:

但在那之后,我如何使用该
AccessToken
获取
用户凭证
?或使用刷新令牌获取
凭证的任何直接方式。任何例子或建议


谢谢

您可能想尝试使用客户机库来处理这个而不是那个。您只需运行以下代码一次。刷新令牌将由
FileDataStore
创建,并存储在
%appData%
目录中。下次运行时,它不会提示您进行身份验证,因为它已经拥有了身份验证。您还可以创建自己的
iDataStore
实现,以便在您喜欢的地方存储刷新令牌。我喜欢当前的目录


代码从教程中删除

我不想使用%appData%或任何其他存储。是否可以使用刷新令牌、ClientId和ClientSecret获取UserCredential?您可以创建自己的IDatastore实现,该实现可以根据自己的喜好执行。或者,您可以使用客户端库进行旁路,并在任何c#示例中手动执行旁路过程?如果您进行检查,您将看到如何创建一个将其存储在数据库中的旁路,您应该能够编辑该旁路,以便发送刷新令牌。在这里发帖太大了。
//Scopes for use with the Google Drive API
string[] scopes = new string[] { DriveService.Scope.Drive,
                                 DriveService.Scope.DriveFile};
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
UserCredential credential = 
            GoogleWebAuthorizationBroker
                          .AuthorizeAsync(new ClientSecrets { ClientId = CLIENT_ID
                                                            , ClientSecret = CLIENT_SECRET }
                                          ,scopes
                                          ,"SingleUser"
                                          ,CancellationToken.None
                                          ,new FileDataStore("Daimto.GoogleDrive.Auth.Store")
                                          ).Result;