开发者

Execute FQL Query using Facebook SDK C#

SELECT share_count, like_count, comment_count, total_count
FROM link_stat
WHERE url="http://www.facebook.com/cocacola"

I need to take the above fql query and using the Facbook SDK get the response and assign the response to variable and output to response.write. Visual Studio is giving me issues on the namespace. When it seems I get the namespace working, then .Api is old construct?? Any help achieving my goal would be great.

CODEBEHIND

using Facebook;
using Facebook.Web;


    protected void Page_Load(object sender, EventArgs e)
    {
        var app = new FacebookApp();
        dynamic userInfo = app.Api("/4"); // Mark Zuck
        string firstName = userInfo.first_name;
        string lastName = userInfo.last_name;
        string email = userInfo.email;
        dynamic likes = app.Api("/4/likes");
        foreach (var like in likes.data)
        {
            string name = like.name;
            Response.Write(name);
        }
    }

Ive removed some lines from the above code, th开发者_运维百科e standard VS generated code, to make it smaller. Thanks for your help!


Which version of the Facebook C# SDK do you use? The FacebookApp class has been renamed to FacebookClient in the newer versions, so you should be able to do things like this (in an MVC3 Controller in this case) :

        var fb = new FacebookWebClient(); 
        dynamic me = fb.Get("me");

        ViewBag.id = me.id;
        ViewBag.name = me.name;
        ViewBag.firstname = me.first_name;
        ViewBag.hometown = me.hometown.name;

You can use NuGet to keep the framework up to date. The current version is 5.0.40.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜