public string PrivateReply(string commentId) { try { var client3 = new RestClient("https://graph.facebook.com/v8.0/" + FB_PAGE_ID + "/messages"); var request = new RestRequest(); FacebookPlay.Recipient recipientModel = new FacebookPlay.Recipient(); List <FacebookPlay.Button> buttonModel = new List <FacebookPlay.Button>(); FacebookPlay.Payload payloadModel = new FacebookPlay.Payload(); FacebookPlay.Attachment attachmentModel = new FacebookPlay.Attachment(); FacebookPlay.Message messageModel = new FacebookPlay.Message(); FacebookPlay.Element elementModel = new FacebookPlay.Element(); FacebookPlay.GameMetadata gameMetadataModel = new FacebookPlay.GameMetadata(); FacebookPlay.ShareContents shareContentsModel = new FacebookPlay.ShareContents(); FacebookPlay.Root rootModel = new FacebookPlay.Root(); FacebookPlay.Button2 button2Model = new FacebookPlay.Button2(); FacebookPlay.Element2 element2Model = new FacebookPlay.Element2(); FacebookPlay.Payload2 payload2Model = new FacebookPlay.Payload2(); FacebookPlay.DefaultAction defaultActionModel = new FacebookPlay.DefaultAction(); buttonModel.Add(new FacebookPlay.Button { title = "Naruto", type = "web_url", url = "https://localhost:44366" }); buttonModel.Add(new FacebookPlay.Button { title = "Zoro", type = "web_url", url = "https://localhost:44366" }); payloadModel.template_type = "button"; payloadModel.text = "Chance to win $$$$"; payloadModel.buttons = buttonModel; attachmentModel.type = "template"; attachmentModel.payload = payloadModel; messageModel.attachment = attachmentModel; rootModel.message = messageModel; rootModel.recipient = recipientModel; elementModel.buttons = buttonModel; elementModel.title = "Share"; recipientModel.comment_id = commentId; string recipientJson = JsonConvert.SerializeObject(recipientModel); string messageJson = JsonConvert.SerializeObject(messageModel); request.AddParameter("recipient", recipientJson); request.AddParameter("message", messageJson); request.AddParameter("message_type", "RESPONSE"); request.AddParameter("access_token", FB_ACCESS_TOKEN); // commented for no private replies. var response3 = client3.Post(request); } catch (Exception) { throw; } return(null); }
public string ReplyComment(string commentId, string message) { try { //******************************************************************** /// Send a private message when a person comments on a post in a page. //******************************************************************** var client3 = new RestClient("https://graph.facebook.com/v8.0/" + FB_PAGE_ID + "/messages"); var request = new RestRequest(); FacebookPlay.Recipient recipientModel = new FacebookPlay.Recipient(); List <FacebookPlay.Button> buttonModel = new List <FacebookPlay.Button>(); FacebookPlay.Payload payloadModel = new FacebookPlay.Payload(); FacebookPlay.Attachment attachmentModel = new FacebookPlay.Attachment(); FacebookPlay.Message messageModel = new FacebookPlay.Message(); FacebookPlay.Element elementModel = new FacebookPlay.Element(); FacebookPlay.GameMetadata gameMetadataModel = new FacebookPlay.GameMetadata(); FacebookPlay.ShareContents shareContentsModel = new FacebookPlay.ShareContents(); FacebookPlay.Root rootModel = new FacebookPlay.Root(); FacebookPlay.Button2 button2Model = new FacebookPlay.Button2(); FacebookPlay.Element2 element2Model = new FacebookPlay.Element2(); FacebookPlay.Payload2 payload2Model = new FacebookPlay.Payload2(); FacebookPlay.DefaultAction defaultActionModel = new FacebookPlay.DefaultAction(); buttonModel.Add(new FacebookPlay.Button { title = "Naruto", type = "web_url", url = "https://localhost:44366" }); buttonModel.Add(new FacebookPlay.Button { title = "Zoro", type = "web_url", url = "https://localhost:44366" }); payloadModel.template_type = "button"; payloadModel.text = "Chance to win $$$$"; payloadModel.buttons = buttonModel; attachmentModel.type = "template"; attachmentModel.payload = payloadModel; messageModel.attachment = attachmentModel; rootModel.message = messageModel; rootModel.recipient = recipientModel; elementModel.buttons = buttonModel; elementModel.title = "Share"; recipientModel.comment_id = commentId; string recipientJson = JsonConvert.SerializeObject(recipientModel); string messageJson = JsonConvert.SerializeObject(messageModel); request.AddParameter("recipient", recipientJson); request.AddParameter("message", messageJson); request.AddParameter("message_type", "RESPONSE"); request.AddParameter("access_token", FB_ACCESS_TOKEN); // commented for no private replies. var response3 = client3.Post(request); //var content = response3.Content; // Raw content as string //*************************************************************** /// Reply to a comment in a post in a page. //*************************************************************** Uri uri = new Uri(FB_BASE_ADDRESS + commentId + "/comments"); string myparameters = string.Format("message={0}&access_token={1}", message, FB_ACCESS_TOKEN); using (WebClient client = new WebClient()) { client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var response = client.UploadString(uri, myparameters); } /**************************************************************** **************-----------LIKE THE COMMENTS----------************ **************************************************************** */ uri = new Uri(FB_BASE_ADDRESS + commentId + "/likes"); myparameters = string.Format("access_token={0}", FB_ACCESS_TOKEN); using (WebClient client = new WebClient()) { client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var response = client.UploadString(uri, myparameters); } } catch (Exception) { throw; } return(null); }