Hi all I am trying to post an open graph action to facebook using a HttpWebRequest method.
Here’s my request method
public static string RequestUrl(string action, String HTTPMETHOD, dynamic postdata = null)
{
string results = "";
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(action);
if (HTTPMETHOD == "GET")
{
req.Method = WebRequestMethods.Http.Get;
}
else if (HTTPMETHOD == "POST")
{
ASCIIEncoding encoding = new ASCIIEncoding();
req.Method = WebRequestMethods.Http.Post;
byte[] data = encoding.GetBytes(postdata.sneaqer);
req.ContentLength = data.Length;
req.ContentType = "application/x-www-form-urlencoded";
Stream newStream = req.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
else if (HTTPMETHOD == "DELETE")
{
req.Method = "DELETE";
ASCIIEncoding encoding = new ASCIIEncoding();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
results = sr.ReadToEnd();
sr.Close();
}
catch (Exception ex)
{
Error.Log("ERROR: Common.cs requestUrl() " + ex.Message + " " + action);
}
return results;
}
This is what I have tried so far
var url = "https://graph.facebook.com/" + personFacebookUserId + "/verbNamespace:follow";
dynamic parameters = new System.Dynamic.ExpandoObject();
parameters.person = "http:" + Configuration.getConfigValue("SiteUrl") + "OG/OpenGraphAction.aspx?type=follow&facebookProfilePicture=" + friendFacebookUserId;
string result = Common.RequestUrl(url, "POST", parameters);
I get an error server returned a bad request. I think the problem is the way I am passing in the parameters. The person is the object and follow is the action.
Thanks for any help.
I found this guys article very useful Using ASP.Net with Facebook’s Graph API and OAuth 2.0 Authentication Seems you have to get a auth token by having them redirect to one of your pages.