开发者

How can I publish on a user Facebook wall?

I am trying to publish on a users's facebook wall. I have to do it in asp.net w开发者_高级运维ith c#. Does anyone have a working project? Need step by step help. I tried several projects and no success. The current project i am trying returns 400 bad request error after first post. So, I repeat, I need a working project which does not return errors and not a website name, thanks, adrian


Here is the questioner(transportinoradea): Well, finally i used Facebook Api plus another method instead of CallRequest<> which gave me 400 error. now I handled it, everything is ok.

/// <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 "";
}


I don't know if anyone has written a Facebook API for asp or c# but can't you just do it with basic HTTP requests?

From http://developers.facebook.com/docs/reference/api/:

"You can publish to the Facebook graph by issuing HTTP POST requests to the appropriate connection URLs, using an access token. "

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜