terça-feira, 28 de julho de 2015

Facebook Application C#




  public string LikeFacebook()
        {
            ServiceConfigurationClient serviceConf = new ServiceConfigurationClient();
            dynamic me = (dynamic)Session["me"];
            string facebookId = me.id;

            try
            {
                var fb = new FacebookClient(Session["accessTokenFacebook"].ToString());

                var parameters = new Dictionary<string, object>
            {                               
                { "object" , "https://fb.lapuinka.com.br"} // site               
               
            };

                var Response = fb.Post("https://graph.facebook.com/me/og.likes", parameters);

                bool aux = serviceConf.insertFacebookIdLike(facebookId);

                return "SUCCESS";
            }
            catch (Exception ex)
            {               
                try
                {
                    string likeID = ex.Message.Substring(ex.Message.IndexOf("ID:") + 4);
                    var fb = new FacebookClient(Session["accessTokenFacebook"].ToString());
                    fb.Delete("https://graph.facebook.com/" + likeID);

                    bool aux = serviceConf.deleteFacebookLiked(facebookId);
                    return "DELETED";
                }
                catch(Exception exp)
                {
                    return exp.Message;
                }
            }


        }

      private bool verifyLike()
        {
            try
            {
                ServiceConfigurationClient serviceConf = new ServiceConfigurationClient();
                dynamic me = (dynamic)Session["me"];
                string facebookId = me.id;

                bool aux = serviceConf.isFacebookLiked(facebookId);
                if (aux)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }

        }

Postar um comentário