fb.Get()不存在? [英] fb.Get() doesn't exist?

查看:265
本文介绍了fb.Get()不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面,我从关中的 Prabir的博客(codePLEX文档)和fb.get()方法不存在......我能测试一路攀升到认证的地方需要我到FB登录页面,现在我要做的fb.Get(/我);我是新来的这一点,我只是按照指导...

 私人无效PhoneApplicationPage_Loaded(对象发件人,RoutedEventArgs E)
{
    字符串的appid =XXX;
    字符串[] extendedPermissions =新的[] {publish_stream,offline_access};

    VAR的OAuth =新FacebookOAuthClient {的AppId = APPID};

    VAR参数=新字典<字符串,对象>
    {
        {RESPONSE_TYPE,令牌},
        {显示器,弹出}
    };

    如果(extendedPermissions =空&安培;!&安培; extendedPermissions.Length大于0)
    {
        VAR范围=新的StringBuilder();
        scope.Append(的string.join(,,extendedPermissions));
        参数[范围] = scope.ToString();
    }

    VAR loginUrl = oauth.GetLoginUrl(参数);

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

私人无效webBrowser_Navigated(对象发件人,NavigatingEventArgs E)
{
    FacebookOAuthResult结果= NULL;

    如果(FacebookOAuthResult.TryParse(e.Uri,出结果))
    {
        如果(result.IsSuccess)
        {
            VAR accesstoken = result.AccessToken;
            变种FB =新FacebookClient(accesstoken);

            VAR的结果=(IDictionary的<字符串,对象>)fb.Get(/我);
            VAR名称=(字符串)结果[名称];

            的MessageBox.show(你好+姓名);
        }
        其他
        {
            VAR ErrorDescription中= result.ErrorDescription;
            VAR errorReason = result.ErrorReason;
        }
    }
}
 

解决方案

使用fb.GetAsync代替。窗口电话7不支持同步的方法。

我强烈建议您下载源$ C ​​$ c和检出的Samples \ CS-WP7.sln的例子。

 变种FB =新FacebookClient(_accessToken);

fb.GetCompleted + =(0,参数)=>
                       {
                           如果(args.Error == NULL)
                           {
                               VAR我=(IDictionary的<字符串,对象>)args.GetResultData();

                               Dispatcher.BeginInvoke(
                                   ()=>
                                   {
                                       FirstName.Text =名字:+我[如first_name];
                                       LastName.Text =姓+我[姓氏];
                                   });
                           }
                           其他
                           {
                               Dispatcher.BeginInvoke(()=>的MessageBox.show(args.Error.Message));
                           }
                       };

fb.GetAsync(我);
 

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;
        }
    }
}

解决方案

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");

这篇关于fb.Get()不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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