我正试图在用户的Facebook墙上发布。我必须使用c#在asp.net中完成。有人有工作项目吗?需要一步一步的帮助。我尝试了几个项目而没有成功。我正在尝试的当前项目在第一次发布后返回400错误请求错误。 所以,我再说一遍,我需要一个不会返回错误而不是网站名称的工作项目, 谢谢, 阿德里安
答案 0 :(得分:1)
这是提问者(transportinoradea): 好吧,最后我使用Facebook Api加上另一种方法而不是CallRequest<>这给了我400错误。现在我处理了,一切都好。
/// <summary>
///
/// </summary>
/// <param name="accessToken"></param>
/// <param name="message"></param>
/// <param name="link"></param>
/// <param name="picture"></param>
/// <param name="title"></param>
/// <param name="linkCaption"></param>
/// <param name="description"></param>
/// <returns> Will return empty string if is ok, else will return error message</returns>
public string PublishToFbWall(String accessToken, String message, String link, String picture, String title, String linkCaption, String description)
{
String postData = "";
if (accessToken == "")
return "Access token empty.";
postData += "access_token=" + accessToken;
if (message != "")
postData += "&message=" + message;
if (link != "")
postData += "&link=" + link;
if (picture != "")
postData += "&picture=" + picture;
if (title != "")
postData += "&title=" + title;
if (linkCaption != "")
postData += "&linkCaption=" + linkCaption;
if (description != "")
postData += "&description=" + description;
//postData += "&link=" + "http://www.transportinoradea.ro/";
//postData += "&picture=" + "http://www.transportinoradea.ro/images/logo_transportinoradea_240_100.png";
//postData += "&name=" + "tttt";
//postData += "&caption=" + "linkCaption";
//postData += "&description=" + "description as ds";
return DoFacebookWebrequest(postData, "https://graph.facebook.com/me/feed");
}
/// <summary>
/// Prepare web request...
/// </summary>
/// <param name="postData"></param>
/// <param name="url"></param>
/// <returns> Will return empty string if is ok, else will return error message</returns>
//private string DoFacebookWebrequest(String postData, String url, string accessToken, string message)
private string DoFacebookWebrequest(String postData, String url)
{
try
{
WebClient wcc = null;
try
{
wcc = new WebClient();
wcc.UploadString("https://graph.facebook.com/me/feed", null, postData);
}
catch (System.Net.WebException ex)
{
StreamReader readStream = new StreamReader(ex.Response.GetResponseStream());
//This way wee can see the error message from facebook
string ErrorMessageJson = readStream.ReadToEnd();
JavaScriptSerializer ser = new JavaScriptSerializer();
ErrorFacebook facebookError = ser.Deserialize<ErrorFacebook>(ErrorMessageJson);
//throw new Exception(
return "Error:" + " type(" + facebookError.error.type + "), message:" + facebookError.error.message + " ";
//);
}
}
catch (Exception e)
{
return e.Message;
//throw new Exception(e.ToString());
}
return "";
}
答案 1 :(得分:0)
我不知道是否有人为asp或c#编写了一个Facebook API,但你不能只用基本的HTTP请求吗?
来自http://developers.facebook.com/docs/reference/api/:
“您可以使用访问令牌向相应的连接URL发出HTTP POST请求,从而发布到Facebook图表。”
答案 2 :(得分:0)
我担心你可能没有准备好制作项目,但是样本解释了如何实现这一目标。
我建议您查看this链接,它会帮助您开始使用。