【问题标题】:GooglePlus Authentication in Windows Phone 8.1Windows Phone 8.1 中的 GooglePlus 身份验证
【发布时间】:2015-03-17 18:59:45
【问题描述】:

我正在编写一个 Windows Phone 8.1 应用程序 (WINRT)。 如何在不使用 MVVM/MVC** 的情况下在 Windows Phone 8.1 App** 中进行 GooglePlus 身份验证(通过 GooglePlus 登录)

我在 Windows Phone 8.0 应用程序中使用 通过 Webbrowser 控件进行 Web 身份验证,但 Windows Phone 8.1 WebView 控件没有导航事件。 p>

谁能帮帮我?


根据 Filip Skakun 先生的说法,我写道:

    using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.ApplicationModel.Activation;
using Windows.Data.Json;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Security.Authentication.Web;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Web.Http;


namespace webbrokerFinal
{

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            Connect();


            this.NavigationCacheMode = NavigationCacheMode.Required;
        }


        string FacebookClientIDString = "000000000000";
        string FacebookCallbackUrlString = " https://www.facebook.com/connect/login_success.html";

        private  void Connect()
        {
            try
            {
                String FacebookURL = "https://www.facebook.com/dialog/oauth?client_id=" + FacebookClientIDString + "&redirect_uri=" + Uri.EscapeUriString(FacebookCallbackUrlString) + "&scope=read_stream&display=popup&response_type=token";

                System.Uri StartUri = new Uri(FacebookURL);
                System.Uri EndUri = new Uri(FacebookCallbackUrlString);

                WebAuthenticationBroker.AuthenticateAndContinue(StartUri, EndUri, null, WebAuthenticationOptions.None);

            }
            catch (Exception Error) >> The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
            {
                //
                // Bad Parameter, SSL/TLS Errors and Network Unavailable errors are to be handled here.
                //
            }



        }


        public async void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args)
        {
            WebAuthenticationResult result = args.WebAuthenticationResult;


            if (result.ResponseStatus == WebAuthenticationStatus.Success)
            {
                await GetFacebookUserNameAsync(result.ResponseData.ToString());
            }
            else if (result.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
            {
            }
            else
            {
            }
        }

        private async Task GetFacebookUserNameAsync(string webAuthResultResponseData)
        {
            //Get Access Token first
            string responseData = webAuthResultResponseData.Substring(webAuthResultResponseData.IndexOf("access_token"));
            String[] keyValPairs = responseData.Split('&');
            string access_token = null;
            string expires_in = null;
            for (int i = 0; i < keyValPairs.Length; i++)
            {
                String[] splits = keyValPairs[i].Split('=');
                switch (splits[0])
                {
                    case "access_token":
                        access_token = splits[1]; //you may want to store access_token for further use. Look at Scenario5 (Account Management).
                        break;
                    case "expires_in":
                        expires_in = splits[1];
                        break;
                }
            }

            //Request User info.
            HttpClient httpClient = new HttpClient();
            string response = await httpClient.GetStringAsync(new Uri("https://graph.facebook.com/me?access_token=" + access_token));
            JsonObject value = JsonValue.Parse(response).GetObject();
            string facebookUserName = value.GetNamedString("name");


        }
    }
}

但是给我错误: 远程过程调用失败。 (HRESULT 的异常:0x800706BE)

【问题讨论】:

    标签: c# windows-runtime windows-phone-8.1 google-oauth google-plus-signin


    【解决方案1】:

    我会从WebAuthenticationBroker 开始。它是您用于所有 OAuth 的 WebView 的一种包装器。

    【讨论】:

    • 你分享的链接有一个facebook的例子,但是你能帮我在linkedIn认证和googlePlus认证吗?
    • Giving error 远程过程调用失败。 (HRESULT 异常:0x800706BE)执行 WebAuthenticationBroker.AuthenticateAndContinue(StartUri, EndUri, null, WebAuthenticationOptions.None);
    • Google、Twitter、Facebook 和 Flickr 的示例在这里:code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122
    猜你喜欢
    • 2015-06-11
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-24
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多