Câu trả lời tuyệt vời Richard. Điều này thực sự đã giúp rất nhiều.
Tôi nhận thấy một vài nhận xét từ những người phàn nàn rằng họ không thể tìm thấy sự kiện InitializedCompleted. Nếu bạn đang mã hóa trong .Net 4.5 thì bạn cần phải làm theo mẫu async/await cho các phương thức không đồng bộ. Các lớp ở trên sẽ giống như thế này:
public class LiveLogin
{
private static readonly string[] Scopes =
new[]
{
"wl.signin",
"wl.basic",
"wl.calendars",
"wl.calendars_update",
"wl.contacts_calendars",
"wl.events_create"
};
private LiveAuthClient _authClient;
public async Task<LiveConnectClient> Login()
{
_authClient = new LiveAuthClient("**your client id here**");
LiveLoginResult result = await _authClient.InitializeAsync(Scopes);
if (result.Status == LiveConnectSessionStatus.Connected)
{
return new LiveConnectClient(result.Session);
}
result = await _authClient.LoginAsync(Scopes);
if (result.Status == LiveConnectSessionStatus.Connected)
{
return new LiveConnectClient(result.Session);
}
return null;
}
}
MS có một async chờ mồi here
Nguồn
2013-04-07 08:42:00
tín dụng cho: http://social.msdn.microsoft.com/Forums/en-GB/messengerconnect/thread/ a1ae8e9c-47a5-4bd8-b821-33dc1a0d6e94 – Richard
Cảm ơn. Microsoft nên ghi lại nó. – ashraf
Cảm ơn rất nhiều vì đoạn mã ngắn và ngọt ngào này. Tôi đã không nhận được một ý tưởng rõ ràng về cách sử dụng LiveAuthClient. Tài liệu MSDN mới cho Live SDK rất sai, [LiveAuthClient (String) method] [1] nói tham số chuỗi là URI chuyển hướng. Nó không đề cập đến bất cứ điều gì về ClientID. [1] http://msdn.microsoft.com/en-us/library/live/microsoft.live.liveauthclient.aspx – Adarsha