I'm using the example code from http://msdn.microsoft.com/en-us/library/dn631823.aspx to perform the signing in ahead of performing any OneDrive operations. It seemed to work while I was initially coding but now that I've gone back to it after a break, any attempt to (say) read a folder gives me the error:
The access token that was provided has expired.
The code I'm using to log in is:
currentSession = null;
try
{
var authClient = new LiveAuthClient();
LiveLoginResult result = await authClient.LoginAsync(new string[] { "wl.signin", "wl.skydrive" });
if (result.Status == LiveConnectSessionStatus.Connected)
{
currentSession = result.Session;
Debug.WriteLine("... succeeeded");
}
else
Debug.WriteLine("... not connected, status is {0}", result.Status);
}
catch (LiveAuthException ex)
{
// Display an error message.
Debug.WriteLine("LiveAuthException: {0}", ex.Message);
}
catch (LiveConnectException ex)
{
// Display an error message.
Debug.WriteLine("LiveConnectException: {0}", ex.Message);
}
where currentSession is declared as a private variable in the class and it then gets used in the folder code:
LiveConnectClient liveClient = new LiveConnectClient(currentSession);
LiveOperationResult operationResult = await liveClient.GetAsync("me/skydrive");
dynamic result = operationResult.Result;
What is slightly worrying me is that the documentation says:
Create a LiveAuthClient object and call the InitializeAsync method to initialize the Live SDK. Then call the LoginAsync method with the wl.signin and wl.skydrive scopes to enable single sign-in and allow the user to access OneDrive.
but the sample code DOESN'T make any reference to InitializeAsync and there seem to be variations on the call so it isn't really clear which one (if any) I should use.
This is for a Universal App, although currently I'm just working on the WP8.1 C#/XAML part of it. I'm using Live SDK 5.6.
Thanks.
As noted in the comment I added, it looks highly likely that the "expired token" error was being caused by an incorrect date/time setting on the emulator.