Skydrive wp7 App:GetAsync方法停止工作

时间:2013-11-19 20:27:58

标签: c# windows-phone-7 onedrive

在我的Windows Phone 7芒果应用程序上,我使用Microsoft.Live和Microsoft.Live.Controls引用在Skydrive上下载和上传。登录和上传文件工作正常,但只要我调用“client.GetAsync(”/ me / skydrive / files“);”在LiveConnectClient上,Callback结果为空,只包含错误:“检索资源时发生错误。请稍后再试。”

我尝试使用此方法检索文件列表。

这个错误突然发生而没有对应用程序的源代码进行任何更改(我认为..)直到最近才工作了很长时间。至少我没有更改代码部分进行上传或下载。

我尝试了Skydrive的“两步验证”,仍然是相同的:可以登录但不能下载。 同时将实时参考更新为5.5并没有改变任何内容。

这是我使用的代码。错误发生在“e”变量的“getDir_Callback”中。 范围(wl.skydrive wl.skydrive_update)和clientId在SignInButton中指定,触发“btnSignin_SessionChanged”。

private void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
    {
        if (e.Status == LiveConnectSessionStatus.Connected)
        {
            connected = true;

            processing = true;
            client = new LiveConnectClient(e.Session);

            client.GetCompleted +=  new EventHandler<LiveOperationCompletedEventArgs>(OnGetCompleted);
            client.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(UploadCompleted);
            client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompleted);
            client.DownloadProgressChanged += new EventHandler<LiveDownloadProgressChangedEventArgs>(client_DownloadProgressChanged);

            infoTextBlock.Text = "Signed in. Retrieving file IDs...";
            client.GetAsync("me");


        }
        else
        {
            connected = false;
            infoTextBlock.Text = "Not signed into Skydrive.";
            client = null;
        }
    }


    private void OnGetCompleted(object sender, LiveOperationCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            client.GetCompleted -= new EventHandler<LiveOperationCompletedEventArgs>(OnGetCompleted);
            client.GetCompleted += getDir_Callback;
            client.GetAsync("/me/skydrive/files");

            client_id = (string)e.Result["id"];

            if (e.Result.ContainsKey("first_name") && e.Result.ContainsKey("last_name"))
            {
                if (e.Result["first_name"] != null && e.Result["last_name"] != null)
                {
                    infoTextBlock.Text = "Hello, " +
                        e.Result["first_name"].ToString() + " " +
                        e.Result["last_name"].ToString() + "!";
                }
            }
            else
            {
                infoTextBlock.Text = "Hello, signed-in user!";
            }
        }
        else
        {
            infoTextBlock.Text = "Error calling API: " +
                e.Error.ToString();
        }

        processing = false;
    }

    public void getDir_Callback(object s, LiveOperationCompletedEventArgs e)
    {
        client.GetCompleted -= getDir_Callback;

        //filling Dictionary with IDs of every file on SkyDrive
        if (e.Result != null)
            ParseDir(e);

        if (!String.IsNullOrEmpty(e.Error.Message))
            infoTextBlock.Text = e.Error.Message;
        else
            infoTextBlock.Text = "File-IDs loaded";
    }

2 个答案:

答案 0 :(得分:0)

Yo应使用client.GetAsync(“me / SkyDrive / files”,null)代替client.GetAsync(“me”); 这是我的代码,它工作正常。

 private void btnSignIn_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
        {
            try
            {

                if (e.Session != null && e.Status == LiveConnectSessionStatus.Connected)
                {
                    client = new LiveConnectClient(e.Session);
                    client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(client_GetCompleted);
                    client.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(client_UploadCompleted);
                    client.GetAsync("me/SkyDrive/files", null);
                    client.DownloadAsync("me/SkyDrive", null);
                    canUpload = true;
                    ls = e.Session;

                }
                else
                {
                    if (client != null)
                    {
                        MessageBox.Show("Signed out successfully!");
                        client.GetCompleted -= client_GetCompleted;
                        client.UploadCompleted -= client_UploadCompleted;
                        canUpload = false;
                    }
                    else
                    {
                        canUpload = false;
                    }
                    client = null;
                    canUpload = false;

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

void client_GetCompleted(object sender, LiveOperationCompletedEventArgs e)
        {
            try
            {
                List<System.Object> listItems = new List<object>();
                if (e.Result != null)
                {
                    listItems = e.Result["data"] as List<object>;
                    for (int x = 0; x < listItems.Count(); x++)
                    {
                        Dictionary<string, object> file1 = listItems[x] as Dictionary<string, object>;
                        string fileName = file1["name"].ToString();
                        if (fileName == lstmeasu[0].Title)
                        {
                            folderID = file1["id"].ToString();
                            folderAlredyPresent = true;
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("An error occured in getting skydrive folders, please try again later.");
            }
        }

答案 1 :(得分:0)

在我不改变任何代码的情况下奇迹般地再次运作。它似乎在另一端解决了。我不知道出了什么问题。