LiveConect Auth(适用于 SkyDrive) NullReferenceException (WTH)? [英] LiveConect Auth (for SkyDrive) NullReferenceException (WTH)?

查看:35
本文介绍了LiveConect Auth(适用于 SkyDrive) NullReferenceException (WTH)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在第 9 频道网站上观看了 43 分钟的视频教程并阅读了 LiveConnect 页面,其中显示了代码,但我没有发现我做错了什么.它不断给我一个 NullReferenceException 错误,它甚至没有提出你想允许应用程序 X 访问 Skydrive"的事情,它只是立即中断.我到处都设置了断点,但什么都没有.只是 null,到处都是 null.

I followed a 43 minute video tutorial on the Channel 9 site and read the LiveConnect page where it shows code and I don't see what I'm doing wrong. It keeps giving me a NullReferenceException error and it doesn't even bring up the "Do you want to allow app X to access skydrive" thing, it just breaks immediately. I've set breakpoints everywhere but there is nothing. Just null, null everywhere.

OnNavigatedTo 事件:

OnNavigatedTo event:

LoadProfile();

private async void LoadProfile()
{
try
            {
                LiveAuthClient auth = new LiveAuthClient();
                LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });
                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    this.pageTitle.Text = "Signed in.";
                }
            }
            catch (LiveAuthException exception)
            {
                this.pageTitle.Text = "Error signing in: " + exception.Message;
            }
}

异常说:

推荐答案

我终于找到了解决方案.

I finally found a solution.

订阅按钮点击事件或其他事件,然后使用以下代码:

Subscribe to a button-click event or whatever, then use this code:

LoadProfile();

LoadProfile();

调用这个方法:

public async void LoadProfile()
        {
            try
            {
                LiveAuthClient auth = new LiveAuthClient();
                LiveLoginResult initializeResult = await auth.InitializeAsync();
                try
                {
                    LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });
                    if (loginResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveConnectClient connect = new LiveConnectClient(auth.Session);
                        LiveOperationResult operationResult = await connect.GetAsync("me");
                        dynamic result = operationResult.Result;
                        if (result != null)
                        {
                            this.pageTitle.Text = string.Join(" ", "Hello", result.name, "!");
                        }
                        else
                        {
                            this.pageTitle.Text = "Error getting name.";
                        }
                    }
                }
                catch (LiveAuthException exception)
                {
                    this.pageTitle.Text = "Error signing in: " + exception.Message;
                }
                catch (LiveConnectException exception)
                {
                    this.pageTitle.Text = "Error calling API: " + exception.Message;
                }
            }
            catch (LiveAuthException exception)
            {
                this.pageTitle.Text = "Error initializing: " + exception.Message;
            }

        }

在调试之前,将您的应用添加到 Windows 应用商店仪表板.然后返回到 Visual Studio,在解决方案资源管理器中找到 Package.appxmanifest 并添加 Internet 功能.然后转到项目"菜单 >商店">将应用与商店关联".

Before you debug, add your app to the Windows Store Dashboard. Then go back to Visual Studio, find Package.appxmanifest in Solution Explorer and add the Internet Capability. Then go to the Project menu > Store > Associate App with the Store.

在出现的应用列表中找到您的应用名称,选择它并单击下一步/完成,然后进行调试.现在应该可以正常工作了.

Find your app's name in the list of apps that appears, select it and click Next/Finish and then debug. It should now be working.

这篇关于LiveConect Auth(适用于 SkyDrive) NullReferenceException (WTH)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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