Tuesday, November 22, 2011

Remove a post from Facebook fan page using C# SDK

Wondering how to delete (or) remove a post (or) comment from a facebook fan page wall, here it is!

///<summary\>
/// Remove post from facebook fanpage wall
///</summary\>
///<param name="accesstoken"\>user access token</param>
///<param name="fanPageId"\>Fan Page Id</param>
///<param name="contentId"\>Post or Comment Id </param>
public void removePost(string accesstoken, string fanPageId, string contentId)
{
       var fb = new FacebookClient();
       dynamic parameters = new ExpandoObject();
       parameters.access_token = accesstoken;
       parameters.uid = fanPageId;
       //pass the content id you like to remove - pageid_postid format
     if(fb.Delete("/" + contentId, parameters))
       {

                  Console.Write("Delete Success!");
       }
       else
       {
                  Console.Write("Delete failed!");
       }
}
 
Call this method and the content is cleaned (removed) from your fanpage wall.

Happy coding!

2 comments:

  1. Thanks a lot buddy it works for me after some modification in the code

    if(fb.Delete(contentId, parameters))

    ReplyDelete
  2. Hello Im Osama from MyRouter you can now use MyRouter for virtual router for more details please visit our website

    http://myroutervwr.info/

    thank you very much

    ReplyDelete