在WP7商店LiveConnectSession [英] Store LiveConnectSession in WP7

查看:115
本文介绍了在WP7商店LiveConnectSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Hotmail的API在我的Windows Phone 7应用程序。因此,我要授予访问我的移动应用程序。我这样做,使用微软Live连接API ,这真的伟大工程开始。我使用的身份验证下面的代码:

 的String [] = requiredScope {wl.signin,wl.calendars_update wl.offline_access}; 
LiveAuthClient AUTH =新LiveAuthClient(Configuration.ClientID);
auth.LoginCompleted + =新的EventHandler< LoginCompletedEventArgs>(authInitializeCompletedHandler);
auth.LoginAsync(requiredScope);



客户端ID是我从微软得到了注册我的应用程序的ID。我的回调看起来(简单)是这样的:

 私人无效authInitializeCompletedHandler(对象发件人,LoginCompletedEventArgs E)
{
如果(e.Status == LiveConnectSessionStatus.Connected)
{
this._session = e.Session; //会话帽子的accessToken UND RefreshToken
this._isAuthorized = TRUE;
callDelegates();
}
}

如果该调用成功(而且目前它,所以的作品),我保存获取的会话。本次会议可以在LiveConnectClient构造用来启用与MS API的,在我的应用程序中的Hotmail API的通信。

  LiveConnectClient客户端=新LiveConnectClient(_session); 



我的问题是,我想以某种方式保存会话,因此当应用程序被墓碑,并得到其重点回来了,我不希望用户的许可再问 - 他已经给了我。我有我自己想通了,返回的会话中包含的accessToken,RefreshToken和Expires属性(我知道那是什么,这不是问题)。如何使用在将来调用这些信息?微软的有关文件在这里结束,我无法找到任何有用的信息。



2的解决方法,我发现:




  • 活动连接按钮:不应该是要走的路,因为我不希望显示实时按钮只是让我的会话变量回来。

  • 的RESTful API :这就要求我完全重写了我迄今所做的,因为一切都依赖于LiveConnectClient(这使得通信很容易)。



但我真的不希望使用的解决方法。我相信/希望有一个更好的解决方案。


解决方案

貌似这个问题的答案如下:





  1. 请确保您的应用程序包括wl.signin和wl.offline_access范围。


  2. 如果你不使用的SDK中提供的登入器,你应该始终调用LiveAuthClient.InitializeAsync应用程序启动时。
    仅调用LiveAuthClient.LoginAsync如果InitializeAsync不返回
    A有效的会话。




这些步骤将确保您收到刷新令牌所以没有必要在第一次登录后或同意
提示




来自:
HTTP://social.msdn。 microsoft.com/Forums/en-US/messengerconnect/thread/6df1f31d-a22c-469c-b9f4-5c79e0882701


I want to use the Hotmail API on my Windows Phone 7 App. Therefore, I have to grant access to my mobile app. I do that using the Microsoft Live Connect API, which really works great for the start. I use the following code for authentication:

string[] requiredScope = { "wl.signin", "wl.calendars_update", "wl.offline_access" };
LiveAuthClient auth = new LiveAuthClient(Configuration.ClientID);
auth.LoginCompleted += new EventHandler<LoginCompletedEventArgs>(authInitializeCompletedHandler);
auth.LoginAsync(requiredScope);

ClientID is the ID I got from MS for registering my app. My callback looks (in simple) like this:

private void authInitializeCompletedHandler(object sender, LoginCompletedEventArgs e)
{
    if (e.Status == LiveConnectSessionStatus.Connected)
    {
        this._session = e.Session; // Session hat AccessToken und RefreshToken
        this._isAuthorized = true;
        callDelegates();
    }
}

If that call succeeds (and it currently does, so that works), I store the retrieved Session. This session can be used in the LiveConnectClient constructor to enable the communication with the MS API's, in my app the Hotmail API.

LiveConnectClient client = new LiveConnectClient(_session);

My problem is that I want to save that session somehow, so that when the app is tombstoned and gets its focus back, I don't want the user to ask again for permission - he already gave me that. I have figured out by myself that the returned session contains a AccessToken, RefreshToken and Expires property (I know what that is, that's not the problem). How can I use that information in future calls? Microsoft's documentation about that ends here and I can't find any useful information.

2 workarounds I found:

  • Live Connect Button: Should not be the way to go, because I don't want to show the Live Button just that I get my session variable back.
  • RESTful API: This would require that I completely rewrite what I have done so far because everything relies on the LiveConnectClient (which makes communication pretty easy).

But I don't really want to use that workarounds. I believe/hope that there is a better solution.

解决方案

Looks like the answer to this is as follows

  1. Make sure you applications include both wl.signin and wl.offline_access scopes.

  2. If you're not using the signin control provided in the SDK, you should always call LiveAuthClient.InitializeAsync when the app starts. Only call LiveAuthClient.LoginAsync if InitializeAsync does not return a valid session.

These steps will ensure you receiving a refresh token so no need to prompt for login or consent after the first time.

From: http://social.msdn.microsoft.com/Forums/en-US/messengerconnect/thread/6df1f31d-a22c-469c-b9f4-5c79e0882701

这篇关于在WP7商店LiveConnectSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆