简体   繁体   English

如何在 Windows Phone 8.1 通用应用程序中获取 Google Blogger 访问令牌

[英]How to Get Google Blogger Access Token In Windows Phone 8.1 Universal Apps

I Used The Below code to get access Token But it Throws Method is not implemented.我使用下面的代码来获取访问令牌但它抛出方法没有实现。 How to get Access token Please help me to get access token in windows phone 8.1 Universal Apps如何获取访问令牌 请帮助我在 Windows 手机 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) 
            {

            }
        }

You need to check its official APi document, search "Google Blogger API" for details.您需要查看其官方API文档,搜索“Google Blogger API”了解详情。

I just glanced at the document about authorizing requests and identifying your application, it also use OAuth2.0 protocol, so you need to use the WebAuthenticationBroker class to connect to OAuth provider.我只是看了一眼关于授权请求和识别您的应用程序的文档,它也使用 OAuth2.0 协议,因此您需要使用 WebAuthenticationBroker 类连接到 OAuth 提供程序。

See this sample to get started: https://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122请参阅此示例以开始使用: https : //code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM