Google API 设备和 .NET 的 OAuth 2.0 流程 API

Google API OAuth 2.0 flow for devices and .NET API

我想在为设备使用 OAuth 2.0 流程时使用 Google 的 .NET API。

在为设备使用 OAuth 2.0 流程时,我没有找到任何在 .NET 中使用 GoogleWebAuthorizationBroker 或创建 UserCredentials 对象的方法。

有没有办法满足上述要求?或者我应该只使用 REST API?

谢谢, 罗南

假设您参考此流程:https://developers.google.com/accounts/docs/OAuth2ForDevices,Google API 客户端库不支持 .NET。所以你需要自己构建它,尽管你可以重复使用 Google 的大部分内容。

请注意,"OAuth 2.0 flow for devices" 不是标准化的 OAuth 2.0 流程,因此支持并非无处不在。此外,Google 在别处说:

If your app will run on devices that do not have access to a system browser, or devices with limited input capabilities (for example, if your app will run on game consoles, video cameras, or printers), then see Using OAuth 2.0 for Devices.

如果这确实是你的用例,你应该遵循我的建议,否则你应该切换到 https://developers.google.com/accounts/docs/OAuth2InstalledApp(也请参见右侧的流程图)。

Google API 的 .NET 客户端库支持 OAuth 2.0,它支持多种设备,包括 Windows Phone 8.1 和 Windows Store 应用程序。 OAuth 2.0 文档(包括片段)位于:https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth.

我明显的建议是使用该库,因为它会自动为您刷新令牌(使用存储的刷新令牌)并且它是一个轻型 OO 库,可以为您做很多 "magics"(例如如 media upload).

顺便说一下,我们的 samples repository includes full sample for a universal app, take a look at Blogger.Sample 了解更多详情。