Silverlight WebClient 类返回空字符串

发布于 2024-12-12 22:51:32 字数 966 浏览 2 评论 0原文

我正在尝试在 Silverlight 4 中创建一个基本的“Silverlight 类库”,以使用 Facebook 的 Graph API 返回基本的 Facebook 信息,但我只返回空字符串。 我正在使用以下代码:

string _Response = "";

    public string GetFacebookMe(string access_token)
    {
        WebClient facebookClient = new WebClient();
        facebookClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(facebookClientDownloadStringCompleted);
        facebookClient.DownloadStringAsync(new Uri("https://graph.facebook.com/me" + "?access_token=" + access_token));
        string ret = _Response;

        return ret;
    }

    private void facebookClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            _Response = e.Result;
        }
        else
        {
            _Response = e.Error.Message;
        }
    }

我在调试时尝试对值“Default”进行 init _Response,因此返回了字符串“Default”。我已经搞乱这个有一段时间了,我不确定我哪里出错了。

提前致谢!

I am trying to make a basic 'Silverlight Class Library' in Silverlight 4 to return basic Facebook Information using Facebook's Graph API, but I am only getting empty strings being returned.
I am using the following code:

string _Response = "";

    public string GetFacebookMe(string access_token)
    {
        WebClient facebookClient = new WebClient();
        facebookClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(facebookClientDownloadStringCompleted);
        facebookClient.DownloadStringAsync(new Uri("https://graph.facebook.com/me" + "?access_token=" + access_token));
        string ret = _Response;

        return ret;
    }

    private void facebookClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            _Response = e.Result;
        }
        else
        {
            _Response = e.Error.Message;
        }
    }

I tried while debugging to init _Response to the value "Default", and the string "Default" was consequently being returned. I have been messing with this for a while and I'm not sure where I'm going wrong.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他不在意 2024-12-19 22:51:36

直接使用WebClient意味着要付出很大的努力。使用 Silverlight 和 .Net Framework 4.0 时,您可以使用 Codeplex 上的 Facebook C# SDK

详细介绍了 SDK 的使用在 Prabir Shrestha 的博客中

It means a lot of effort to use directly WebClient. When using Silverlight and .Net Framework 4.0 you may use Facebook C# SDK at Codeplex

Usage of the SDK is excellently covered in this blog by Prabir Shrestha

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文