如何在facebook c#sdk 5.4.1中使用“喜欢”功能?

时间:2012-01-04 15:13:51

标签: c# html facebook sdk facebook-like

在Facebook开发者网站上看起来很容易。只需要对POST_ID /喜欢进行HTTP POST(我得到了帖子i.d)。 在c#sdk v.5.4.1中有一个POST方法,但我无法弄清楚如何使用它并进行正确的调用。

3 个答案:

答案 0 :(得分:3)

查看facebook API文档.. http://developers.facebook.com/

            var fb = new FacebookClient("my token"); 
            dynamic parameters = new ExpandoObject();
            parameters.message = "the publish msg"; 
            dynamic result = fb.Post("/me/feed", parameters); 
            var id = result.id; 
            var res = fb.Post("/" + id + "/likes"); 

答案 1 :(得分:0)

我遇到了同样的问题,所以我尝试了几件事情。这对我有用

var token = "[your access token]";
var fb = new Facebook.FacebookClient(token);

var postId = "173213306032925_745288855492031"; //replace this with your big id which comprises of [userid]_[postid]

Console.WriteLine(fb.Post(id+"/likes", null).ToString());       // should print 'True'

Console.WriteLine(fb.Get("173213306032925_745288855492031/likes").ToString());    //should give you details

答案 2 :(得分:0)

        public void FacebookLike(AppConnect appconnect )
    {
        try
        {
            Dictionary<string, string> tokens = new Dictionary<string, string>();
            string fb_exchange = appconnect.UserToken;
            string url =
            string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&grant_type=fb_exchange_token&fb_exchange_token={3}&redirect_uri=https://www.facebook.com/connect/login_success.html&scope={1}&client_secret={2}",
            appconnect.AppID, appconnect.ExtendedPermissions, appconnect.AppSecret, fb_exchange);
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string vals = reader.ReadToEnd();
                foreach (string token in vals.Split('&'))
                {
                    //meh.aspx?token1=steve&token2=jake&...
                    tokens.Add(token.Substring(0, token.IndexOf("=")),
                        token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                }
            }
            string access_token = tokens["access_token"];
            var client = new FacebookClient(access_token);
            dynamic parameters = new ExpandoObject(); parameters.idobject = "";

            client.Post("/" + appconnect.AppID.ToString() + "_" + appconnect.PostID.ToString() + "/Likes", parameters);
           // MessageBox.Show("....... Done ..........");

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message +"\n"+ex.InnerException);
        }


    }
 class AppConnect
{
    //tring appId, string Appsecret, string userToken, string userID, string PostID

    public string Name { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public  string AppID { get; set; } = "991341734653453831";
    public  string AppSecret { get; set; } = "99dfbf29234ergec4a";
    public string UserID { get; set; } = null;
    public  string UserToken { get; set; } = null; 
    public  string PostID { get; set; } = null;
    public  string ExtendedPermissions { get; set; } = "user_posts, publish_actions, publish_pages,manage_pages,user_likes";
}