0

Я пишу Приложение Windows Phone 8.1 (WINRT). Как сделать Аутентификация GooglePlus (вход через GooglePlus) в Windows Phone 8.1 Приложение ** без использования MVVM/MVC **?Аутентификация GooglePlus в Windows Phone 8.1

Я использовал веб-аутентификации с помощью элемента управления WebBrowser в Windows Phone 8.0 App но Windows Phone 8,1 WebView управления не Навигация событие.

Может ли кто-нибудь мне помочь?


По словам г-на Филипа Скакун, я писал:

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)

ответ

2

Я бы начал с WebAuthenticationBroker. Это своего рода обертка вокруг WebView, которую вы используете для всех OAuth.

+0

ссылка, которую вы поделили, имеет пример facebook, но можете ли вы помочь мне в аутентификации, связанной с идентификацией и googlePlus? –

+0

Ошибка при передаче Удаленный вызов процедуры не выполнен. (Исключение из HRESULT: 0x800706BE) при выполнении WebAuthenticationBroker.AuthenticateAndContinue (StartUri, EndUri, null, WebAuthenticationOptions.None); –

+1

Пример с Google, Twitter, Facebook и Flickr находится здесь: https://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122 – kiewic