2013-12-09 21 views
0

enter image description here我開發了Windows Phone 8應用程序訪問天空drive.i我收到以下錯誤,當我打電話LoginAsync()方法 - 類型的異常「Microsoft.Live.LiveAuthException」發生在mscorlib.ni.dll但在用戶代碼中沒有處理我WP8應用開發的天空驅動器時收到錯誤在LoginAsync方法

using System; 
using System.Windows; 
using Microsoft.Phone.Controls; 
using Microsoft.Live; 
namespace SkyDriveApp 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     // Constructor 
     LiveConnectClient client; 

     public MainPage() 
     { 
      InitializeComponent();    
     } 

     public async void Auth() 
     { 

       string clientId = "My_client_id"; 
       LiveAuthClient auth = new LiveAuthClient(clientId); 
       // var result = await auth.InitializeAsync(new[] { "wl.basic", "wl.signin", "wl.skydrive_update" }); 
       var result = await auth.LoginAsync(new[] { "wl.basic", "wl.signin", "wl.skydrive_update" }); 

       if (result.Status == LiveConnectSessionStatus.Connected) 
       { 
        client = new LiveConnectClient(result.Session); 
        tbMessage.Text = "Connected!"; 
       } 


     } 



     private void btnLogin_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e) 
     { 
      Auth(); 
     } 

    } 

} 
+0

你使用來自https://account.live.com/developers/applications/index正確的客戶端ID?你的應用程序應該設置爲移動客戶端應用程序,你這樣做? –

+0

@igrali是的,我做了它,我有客戶端ID。 –

+0

您是否在清單中啓用了ID_CAP_WEBBROWSERCOMPONENT? –

回答

0

我看到你正在使用提供的登錄布頓,試試這個:
在XAML:

<live:SignInButton Name="skyBtn" ClientId="your client ID" Scopes="wl.signin wl.skydrive wl.skydrive_update" Branding="Skydrive" TextType="Login"/> 

在後面的代碼:

private void skyBtn_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e) 
    { 
    if (e.Status == LiveConnectSessionStatus.Connected) 
    { 
     session = e.Session; 
     client = new LiveConnectClient(session);   
     tbMessage.Text = "Connected!"; 
    } 
    else tbMessage.Text = "Not Connected!"; 

    if (e.Error != null) 
    { 
     tbMessage.Text = "Not Connected!"; 
     Dispatcher.BeginInvoke(() => 
     { 
      MessageBox.Show(e.Error.Message); 
     }); 
    } 
    } 
+0

感謝您的評論,但此代碼給出相同的錯誤。 –

+1

然後它似乎是類似的問題就像這裏:http://stackoverflow.com/questions/20435515/a-first-chance-exception-of-type-microsoft-live-liveauthexception-occurred-in?noredirect=1#comment30537194_20435515你能夠檢查與其他電腦嗎?也許代碼沒有問題,但有連接。 – Romasz

+0

我在另一臺帶有vs10和wp7的電腦上試過這段代碼。這段代碼完全可以在那臺電腦上運行。但是我想在我的電腦上使用它,我安裝了vs2012和wp8.可以幫助我。 –

相關問題