【问题标题】:How to Get Google Blogger Access Token In Windows Phone 8.1 Universal Apps如何在 Windows Phone 8.1 通用应用程序中获取 Google Blogger 访问令牌
【发布时间】:2015-07-10 04:14:49
【问题描述】:

我使用下面的代码来获取访问令牌但是它抛出方法没有实现。如何获取访问令牌请帮我在 windows phone 8.1 通用应用程序中获取访问令牌

StringBuilder authLink = new StringBuilder();

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token");
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.Method = "POST";
            authLink.AppendFormat("code={0}", "code");
            authLink.AppendFormat("&client_id={0}", "xxxxxxxxxx.apps.googleusercontent.com");
            authLink.AppendFormat("&client_secret={0}", "xxxxxxxxxx");
            authLink.AppendFormat("&redirect_uri={0}", "urn:ietf:wg:oauth:2.0:oob");
            authLink.Append("&grant_type=authorization_code");
            UTF8Encoding utfenc = new UTF8Encoding();
            byte[] bytes = utfenc.GetBytes(authLink.ToString());
            Stream os = null;

            try // send the post
            {
                 // Count bytes to send
                os =await webRequest.GetRequestStreamAsync();
                os.Write(bytes, 0, bytes.Length);        // Send it
            }
            catch (Exception ex) 
            {
            }
            try // get the response
            {
                HttpWebResponse webResponse =(HttpWebResponse)await webRequest.GetResponseAsync();
                if (webResponse == null) 
                {

                }
                StreamReader sr = new StreamReader(webResponse.GetResponseStream());
                String Text = sr.ReadToEnd().Trim();
                //MessageBox.Show(sr.ReadToEnd().Trim());
            }
            catch (Exception ex) 
            {

            }
        }

【问题讨论】:

    标签: c# windows-runtime windows-phone-8.1


    【解决方案1】:

    您需要查看其官方API文档,搜索“Google Blogger API”了解详情。

    我只是看了一下关于授权请求和识别你的应用程序的文档,它也是使用 OAuth2.0 协议的,所以你需要使用 WebAuthenticationBroker 类来连接 OAuth 提供者。

    查看此示例以开始使用:https://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-26
      • 2015-04-22
      • 1970-01-01
      • 2014-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多