Google API授权在控制台中运行的应用程序
我想手动授权一个在没有可用浏览器的控制台中运行的应用程序。
基本上,我需要与它们在但是C#等效。
我似乎找不到C#库中的零件,该部分允许我打印到控制台的链接而不是打开浏览器。
我当前的实现我只是打开浏览器,如果不能打开错误。
GoogleClientSecrets? fromStream = await GoogleClientSecrets.FromStreamAsync( stream , taskCancellationToken );
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( fromStream.Secrets
, scopes
, user
, taskCancellationToken
, new FileDataStore( nameof(Authorize) ) );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
googlewebauthorizationbroker.authorizeasync
方法设计用于安装应用程序。已安装的应用程序将打开代码正在运行的机器上的浏览器。以下示例是为Web应用程序设计的。该应用程序需要在Web服务器上运行。
这是您的两个选择,除非您能够使用服务帐户授权。服务帐户授权旨在用于服务器到您的应用程序和您的帐户之间的服务器通信。它不能与所有Google API一起使用。
选项
考虑一次在本地运行代码,然后将FileDatastore创建的凭证文件与您的代码一起在服务器上创建。 google .net - filedatastore demyssified
曾经是打印链接
的方法打印授权链接,但明天我将不得不在图书馆里挖掘。
The
GoogleWebAuthorizationBroker.AuthorizeAsync
method is designed for installed applications. Installed applications will open the browser on the machine the code is running on.The following example is designed for web applications. The application would need to be running on a web server.
These are your two options unless you are able to use service account authorization. Service account authorization is intended for server to server communication between your application and an account you the developer control. It does not work with all google apis.
options
Consider running your code once locally, then copy credentials file that is created by FileDataStore onto the server along with your code. Google .net – FileDatastore demystified
print link
There used to be a method to print the authorization link but i will have to dig around in the library for it tomorrow.