Office 365 API:使用客户端库的Windows 8应用程序

时间:2014-10-20 12:57:37

标签: ms-office preview office365

我尝试使用https://code.msdn.microsoft.com/Office-365-APIs-Windows-8-63a74ba2上提供的客户端库运行Windows 8应用示例,但是我收到了以下错误。

“值不能为null。参数名称:serviceContext”

私有异步任务EnsureClientCreated()         {

        var authenticator = new Authenticator();
        var result = await authenticator.AuthenticateAsync("MyFiles", ServiceIdentifierKind.Capability);

        // Create a client proxy:
        this.client = new SharePointClient(result.ServiceUri, result.GetAccessToken);
        this.client.Context.IgnoreMissingProperties = true;
    }

    /// <summary>
    /// Populates the page with content passed during navigation. Any saved state is also
    /// provided when recreating a page from a prior session.
    /// </summary>
    /// <param name="sender">
    /// The source of the event; typically <see cref="NavigationHelper"/>
    /// </param>
    /// <param name="e">Event data that provides both the navigation parameter passed to
    /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
    /// a dictionary of state preserved by this page during an earlier
    /// session. The state will be null the first time a page is visited.</param>
    private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {
        Exception exception = null;

        try
        {
            this.DefaultViewModel["Items"] = new[] { new { Primary = "Loading...", Secondary = "Please wait..." } };

            IOrderedEnumerable<IFileSystemItem> files = await GetOneDriveFiles();

            if (files == null)
            {
                this.DefaultViewModel["Items"] = null;
            }
            else
            {
                this.DefaultViewModel["Items"] = files.Select(file => new
                {
                    Primary = file.Name,
                    Secondary = "Last modified on " + ToLocalTimeString(file.TimeLastModified)
                });
            }
        }
        catch (Exception ex)
        {
            exception = ex;
        }

        if (exception != null)
        {
            await ShowErrorMessageAsync(exception.Message);
        }
    }

    private async Task<IOrderedEnumerable<IFileSystemItem>> GetOneDriveFiles()
    {
        await EnsureClientCreated();

        // Obtain data:
        var filesRequest = await this.client.Files["Shared with Everyone"].ToFolder().Children.ExecuteAsync();
        var files = filesRequest.CurrentPage.OrderBy(e => e.Name);
        return files;
    }

任何想法?

1 个答案:

答案 0 :(得分:0)

您可以尝试使用可在此处找到的当前工具版本:http://aka.ms/office365apitoolspreview 如果这不能解决问题,那么查看导致问题的特定API调用的HTTP跟踪将会很有帮助。

相关问题