そのため、Windows Phone8アプリケーションをLiveAPIに接続することに成功しました。また、hotmailアカウントからデータを読み取ることにも成功しました。
必要なクライアントIDとライブアクセストークンにアクセスできます。
しかし、アプリケーションを終了して再起動すると、セッションとクライアントオブジェクトへのすべての参照が失われ、プロセスを新たに開始する必要があります。
ユーザーがアプリケーションを起動するたびに必要なアクセス許可を提供することに再度同意する必要があるWebマスクでユーザーを困らせたくありません。しかし、この手順なしでセッションオブジェクトへの参照を取得する方法も見つかりませんでした。
ログインマスクは、アプリケーションのインストール後に初めて表示され、その後は上記の画面のみが表示されます。しかし、それでもユーザーが毎回これを受け入れるのは非常に面倒です。
クラスに標準のコンストラクターがないため、セッションオブジェクトをシリアル化しようとしましたが、これは不可能です。
ライブアクセストークンを使用して新しいセッションを作成することは可能かもしれませんが、その方法が見つかりませんでした。
何か案は?私が間違っているのは、ユーザーにプロンプトを表示せずに再度ログインする方法があることを知っています。私はすべてのアイデアに感謝しています。
私が使用するいくつかのコード:
/// <summary>
/// This method is responsible for authenticating an user asyncronesly to Windows Live.
/// </summary>
public void InitAuth()
{
this.authClient.LoginCompleted +=
new EventHandler<LoginCompletedEventArgs>(this.AuthClientLoginCompleted);
this.authClient.LoginAsync(someScopes);
}
/// <summary>
/// This method is called when the Login process has been completed (successfully or with error).
/// </summary>
private void AuthClientLoginCompleted(object sender, LoginCompletedEventArgs e)
{
if (e.Status == LiveConnectSessionStatus.Connected)
{
LiveConnector.ConnectSession = e.Session; // where do I save this session for reuse?
this.connectClient = new LiveConnectClient(LiveConnector.ConnectSession);
// can I use this access token to create a new session later?
LiveConnector.LiveAccessToken = LiveConnector.ConnectSession.AccessToken;
Debug.WriteLine("Logged in.");
}
else if (e.Error != null)
{
Debug.WriteLine("Error signing in: " + e.Error.ToString());
}
}
LiveAuthClient.InitializeAsync-メソッドを使用して、アプリケーションの再起動後にバックグラウンドでログインしようとしましたが、セッションオブジェクトが空のままになります。
// this is called after application is restarted
private void ReLogin()
{
LiveAuthClient client = new LiveAuthClient(LiveConnector.ClientID);
client.InitializeCompleted += OnInitializeCompleted;
client.InitializeAsync(someScopes);
}
private void OnInitializeCompleted(object sender, LoginCompletedEventArgs e)
{
Debug.WriteLine("***************** Inititalisation completed **********");
Debug.WriteLine(e.Status); // is undefined
Debug.WriteLine(e.Session); // is empty
}
アプリケーションを再起動した後、新しいセッションにアクセスする方法を誰かが知っていますか?