Google+ 使用C#登录Winform

Google+ login Winform using C#

我正在开发一个简单的 Winform 应用程序,允许用户使用他们的 Google 帐户创建一个帐户。我查看了 google Api 的文档,但我不知道它如何与 winforms 一起工作。

应用程序的想法很简单,我有 2 种形式:

  1. 主菜单,带有显示第二种形式的按钮。
  2. WebBrowserForm,此表单包含用于访问google和获取信息的网络浏览器。

你能帮我提供教程或其他任何东西吗?

没有任何开箱即用的东西可以为您做到这一点。官方 Google .net client library 不会为您提供授权 URI 以供您在网络浏览器控件中显示,它会自动在用户默认的网络浏览器中打开它。

这并不意味着这不是你做不到的事情。我有一个应用程序可以做到这一点,但我必须自己从下到上编写它。

我有一个关于我是如何做到的非常古老的教程。它从构建 uri 开始。

public static Uri GetAutenticationURI(string clientId, string redirectUri)
  {
  // separate more then one scope with a space
  string scopes = "https://www.googleapis.com/auth/plus.login email";   
  if (string.IsNullOrEmpty(redirectUri))
   {
   redirectUri = "urn:ietf:wg:oauth:2.0:oob";
   }
 string oauth = string.Format("https://accounts.google.com/o/oauth2/auth?client_id={0}&redirect_uri={1}&scope={2}&response_type=code", clientId, redirectUri, scopes);
return new Uri(oauth);
  }

完整教程Google API and Oauth2

所有要做的就是在您获得用户的刷新令牌后进行身份验证,您只需保存它,然后您就可以再次访问数据。您将不得不检查文档,了解您想从哪些 API 请求数据,只需在每个请求的末尾添加您的访问令牌 access_token=mytoken 或将其添加到请求的 header 即可。