fb.Get() doesn't exist?

China☆狼群 提交于 2019-12-08 02:34:31

问题


I have the code below that I got from off of Prabir's Blog (codeplex documentation) and the fb.get() method does not exist...I was able to test all the way up to authentication where it takes me to the fb login page and now I am trying to do the fb.Get("/me"); I am new to this and am just following the guide...

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    string appId = "xxx";
    string[] extendedPermissions = new[] { "publish_stream", "offline_access" };

    var oauth = new FacebookOAuthClient { AppId = appId};

    var parameters = new Dictionary<string, object>
    {
        { "response_type", "token" },
        { "display", "popup" }
    };

    if (extendedPermissions != null && extendedPermissions.Length > 0)
    {
        var scope = new StringBuilder();
        scope.Append(string.Join(",", extendedPermissions));
        parameters["scope"] = scope.ToString();
    }

    var loginUrl = oauth.GetLoginUrl(parameters);

    webBrowser.Navigating += webBrowser_Navigated;
    webBrowser.Navigate(loginUrl);
}

private void webBrowser_Navigated(object sender, NavigatingEventArgs e)
{
    FacebookOAuthResult result=null;

    if (FacebookOAuthResult.TryParse(e.Uri, out result))
    {
        if (result.IsSuccess)
        {
            var accesstoken = result.AccessToken;
            var fb = new FacebookClient(accesstoken);

            var results = (IDictionary<string, object>)fb.Get("/me");
            var name = (string)results["name"];

            MessageBox.Show("Hi " + name);
        }
        else
        {
            var errorDescription = result.ErrorDescription;
            var errorReason = result.ErrorReason;
        }
    }
}

回答1:


use fb.GetAsync instead. Window Phone 7 doesn't support synchronous methods.

i highly recommend you to download the source code and checkout the "Samples\CS-WP7.sln" example.

var fb = new FacebookClient(_accessToken);

fb.GetCompleted += (o, args) =>
                       {
                           if (args.Error == null)
                           {
                               var me = (IDictionary<string, object>)args.GetResultData();

                               Dispatcher.BeginInvoke(
                                   () =>
                                   {
                                       FirstName.Text = "First Name: " + me["first_name"];
                                       LastName.Text = "Last Name: " + me["last_name"];
                                   });
                           }
                           else
                           {
                               Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
                           }
                       };

fb.GetAsync("me");


来源:https://stackoverflow.com/questions/8548576/fb-get-doesnt-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!