Microsoft.Live.LiveAuthException: User has not granted the application consent to access data in Windows Live - windows-phone-8

Hello I'm writing Windows phone application for working with OneDrive. My code is pretty simple:
XAML:
<OneDrive:SignInButton Name="signInButton1"
Height="72"
Margin="152,436,144,0"
VerticalAlignment="Top"
ClientId="MYCLIENTID"
Scopes="wl.basic wl.photos wl.skydrive wl.offline_access wl.signin wl.skydrive_update"
SessionChanged="signInButton1_SessionChanged"
TextType="Custom" />
CS code:
private void signInButton1_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
{
if (e.Session != null && e.Status == LiveConnectSessionStatus.Connected)
{
Session = e.Session;
}
}
When I push drive sign in button Signin the window is opened and if i don't submit this window but instead just press the back button then the white screen is shown and I get:
An exception of type 'Microsoft.Live.LiveAuthException' occurred in
mscorlib.ni.dll and wasn't handled before a managed/native boundary
User has not granted the application consent to access data in Windows
Live
Could somebody help me with it?

Try upgrading to the LiveSDK 5.6, which was just released a week or two ago. In using a sample Windows Phone 8 app with your code, this exception appears to be handled internally and doesn't get thrown into the UI (aka, I can't repro this with Live SDK 5.6).

Related

Winphone 8.1, Winphone 10 and Moga pro connection

I'm making a game support MogaPro run on both WP10 and WP8.
Here is the Capabilities code on packet manifest
<Capabilities>
<Capability Name="internetClientServer" />
<DeviceCapability Name="proximity" />
</Capabilities>
Create gamepad object:
if (!g_GamePad)
{
try
{
g_GamePad = ref new Moga::Windows::Phone::ControllerManager();
g_GamePad->Connect();
}
catch (Platform::Exception^ e)
{
return false;
}
if (!g_GamePad)
return false;
}
And code check connection:
if ((g_GamePad) && ((Moga::Windows::Phone::ControllerManager^)g_GamePad)->GetState(Moga::Windows::Phone::ControllerState::Connection) == Moga::Windows::Phone::ControllerResult::Connected){//code callback}
The problem is when I run on WP10 device, a system popup appear ask user want to use moga pro on this app or not. If I chose Yes, game run perfect. If I chose No, the Moga and Game never connect until I Uninstall and reinstall app.
But in WP8.1 I doesn't see any confirm popup and can not connect moga pro and game. Always assert at code check connection.
What is different between WP10 and WP8.1, and how I connect Moga and WP8.1.
Please help,
Thanks.
It looks like some incompatibility between MOGA control and Windows Phones; it's not possible to answer your question without access to the MOGA source code, but issue definitely not in your code.
I recommend you to try my open source library: worked perfectly with MOGA Mobile and should work with MOGA Pro.

Windows Phone 10 File Save Picker Not Working

I'm having trouble getting the "file save picker" contract working in Windows Phone 10 for my Universal Windows App. I've added both "File Save Picker" and "Cached File Updater" declarations to the app manifest.
It works fine for me on a full Windows 10 computer (tested Mail and Mobile Word).
When I try it on a phone running WP10, I get a native exception A heap has been corrupted (parameters: 0x77344270) with error code 0xc0000374. No part of the stacktrace leads into my app.
My TargetFileRequested listener:
private async void FileSavePickerUI_TargetFileRequested(
FileSavePickerUI sender,
TargetFileRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
var filePath = GetSelectedFilePath();
args.Request.TargetFile = await StorageFile.GetFileFromPathAsync(filePath);
CachedFileUpdater.SetUpdateInformation(
args.Request.TargetFile,
CachedFileListener.CreateContentId(contentId, destination),
ReadActivationMode.NotNeeded,
WriteActivationMode.AfterWrite,
CachedFileOptions.None);
deferral.Complete();
}
I'm overriding OnCachedFileUpdaterActivated(CachedFileUpdaterActivatedEventArgs args), but it never gets called (app crashes before here).
Again, it only crashes in WP10. Win10 works fine.
Note: sometimes it doesn't appear to crash, but the updater method is still never called.
I have also tried this sample here:
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/FilePickerContracts
And I get similar results in that OnCachedFileUpdaterActivated is only ever called on desktop not phone.

ApplicationClose event

I'm developing Windows 10 universal app in C#/XAML.
I want to implement such a policy, that whenever user closes my app (and some other conditions are met, but its irrelevent here) an adverisment will display.
My question is how can I intercept and cancel/handle an event when application is being closed? This is easy when user decides to close the app by for example pressing a button that I'll define in XAML, but what if he presses Alt+F4? In Winforms this is easy as well:
private void Form1_Load(object sender, EventArgs e)
{
this.FormClosing += Form1_FormClosing;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
But how can I achieve similiar effect in in Windows 10 universal app?
I'm afraid there is no option to cancel the closing of the app or even delay it. The Suspending event is the only indication your app will receive prior to termination (if it happens). Check out the Application.Suspending event: https://msdn.microsoft.com/en-us/library/windows.ui.xaml.application.suspending.aspx
No, you can not achieve the similar effect in Windows 10 Universal App (and Windows 8.1 Store App), because in the modern app, the user have the full control of the app and the app can not stop the user closing a app.
If you have sth need to handle when user closing the application, as Lukkha stated, you can handle them in Application.Suspending, but there is a time limitation by default, all of the things should be done within 5s. If you want to have more than 5s, you need to request a ExtendedExecutionSession.
Using Extended Execution in Windows 10 Universal Apps

Azure Mobile Services authentication not working with Windows Phone 8.1 Universal app

I'm adding Azure Mobile Services authentication to a Universal Windows project. It's all set up and working properly on the server and in the Windows Store version of the app, however I can't get it to work with the Windows Phone 8.1 version of the app. I actually have two different apps that I've been working on with the same problem, so I created a test app based strictly on the steps outlined in this article. The sample app has one button on the UI that will attempt authenticate the user with Twitter when pressed.
The flow that I am seeing from the UI is:
Press the button
Screen goes black for a moment
Screen displays "Resuming..." with a spinner
InvalidOperationException gets caught
The exception details:
System.InvalidOperationException was caught
HResult=-2146233079
Message=Authentication was cancelled by the user.
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceAuthentication.<LoginAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MobileAuthTest.MainPage.<AuthenticateAsync>d__3.MoveNext()
InnerException:
The code I am using is copied almost verbatim from the article, but I'll paste it here too:
private async void Button_Click(object sender, RoutedEventArgs e)
{
await this.AuthenticateAsync();
}
// Define a method that performs the authentication process
// using a Twitter sign-in.
private async Task AuthenticateAsync()
{
while (user == null)
{
string message;
try
{
// Change 'MobileService' to the name of your MobileServiceClient instance.
// Sign-in using Twitter authentication.
user = await App.mobileService
.LoginAsync(MobileServiceAuthenticationProvider.Twitter);
message =
string.Format("You are now signed in - {0}", user.UserId);
}
catch (InvalidOperationException)
{
message = "You must log in. Login Required";
}
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
And this override is in App.xaml.cs:
protected override void OnActivated(IActivatedEventArgs args)
{
// Windows Phone 8.1 requires you to handle the respose from the WebAuthenticationBroker.
#if WINDOWS_PHONE_APP
if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
{
// Completes the sign-in process started by LoginAsync.
// Change 'MobileService' to the name of your MobileServiceClient instance.
mobileService.LoginComplete(args as WebAuthenticationBrokerContinuationEventArgs);
}
#endif
base.OnActivated(args);
}
My testing is all on a real Windows Phone 8.1 device (Nokia 920 with 8.1 update).
It's also worth pointing out that the project I'm currently trying to get this to work in is also using Xamarin.Forms for Android, iOS and Windows Phone (I wanted a comparison between Xamarin.Forms for Windows Phone and Universal apps for Windows Phone). All of the apps work, EXCEPT for the two Windows Phone apps. The Xamarin.Forms Windows Phone app is a Windows Phone Silverlight 8.1 app which acts the same as described above for the Universal WP, but fails with the error, "Authentication failed with HTTP response code 0."
I've searched around and haven't found any other cases of people encountering the same issue I am. Is there something I need to do that is so simple nobody feels the need to say it in writing?
Well, it turns out that the issue I am seeing may just be my device. I sent the sample app to another dev for testing and he had no issues. I also was able to successfully log in with both the sample app and the real app on the simulator. That isn't exactly a thorough test sample, but it's enough for me to stop banging my head on this desk.

Windows Phone 8.1 Voice Commands App Activation

I want to integrate some voice commands in my windows phone 8.1 app.
The first thing I want to do is to open my app by a voice command and navigate to a certain page.
According to MSDN article Quickstart: Voice commands (XAML) I can use the override of protected virtual void OnActivated(IActivatedEventArgs args) method in App.xaml.cs to meet my requirements. But it does'nt work the way I though it would!
I have the method with the following structure:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.VoiceCommand)
{
var commandArgs = args as VoiceCommandActivatedEventArgs;
if (commandArgs != null)
{
// ... some logic here
}
}
}
The problem is when I'm activating my app by saying "Open 'name of my app' [optional words]" the app opens but the Activated event never fires! The app opens and OnLaunched event fires. So I can't even enter the OnActivated method.
Does anyone know the problem? Why can't I enter OnActivated method using voice commands?
P.S. I tried it with a simulator as well as with a real device.
you can see this article,
http://t.co/Q5hRxRPvwR
is in spanish, but you will understand.
After you install the app and run it, the xml should be installed, like said in documentation.
After ask to cortana "What can I say?" it will show all you can said, and the apps that supports cortana. Choose you app and you will see what you can say for your app, like
If you say what your app can listen, your app will be activated.