如何用facebookcsharp sdk查询facebook? (WP8.1通用应用程序)

时间:2015-01-07 09:42:30

标签: c# facebook facebook-c#-sdk win-universal-app

我正在研究WP8.1通用应用程序,我尝试使用facebook c#sdk。

我成功登录Facebook,现在我想进行简单的查询

我测试了这段代码(来自这里http://facebooksdk.net/docs/phone/howtos/run-fql-queries/

private async void OnQueryButtonClick(object sender, RoutedEventArgs e)
{
    var fb = new Facebook.FacebookClient(this.loginButton.CurrentSession.AccessToken);
    var result = await fb.GetTaskAsync("fql",
        new
        { 
            q = "SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25)" 
        });

    System.Diagnostics.Debug.WriteLine("Result: " + result.ToString());
}

但是我收到了这个错误:

  

(OAuthException - #12)(#12)对于版本v2.1和版本,不推荐使用fql   更高

有人可以提供GetTaskAsync的使用样本吗?

: - )

1 个答案:

答案 0 :(得分:0)

var fb - new FacebookClient(this.loginButton.CurrentSession.AccessToken);
fb.GetTaskAsync
(
    "fql",
    new
    { 
        q = "SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25)" 
    }
).ContinueWith
(
    t=> 
    if(!t.IsFaulted) 
    {
        dynamic result = t.Result;
        System.Diagnostics.Debug.WriteLine("Result: " + result.ToString());
    }
);

我没有编译上面的代码,但这应该适用于简单的Async GetTask调用。注意我建议远离fql facebook api调用。 FQL将随着下一版本的Facebook Graph API(https://developers.facebook.com/docs/reference/fql/)批量查询而无法复杂的FQL查询。