【问题标题】:How can I publish on a user Facebook wall?如何在用户 Facebook 墙上发布?
【发布时间】:2011-09-09 08:33:59
【问题描述】:

我正在尝试在用户的 Facebook 墙上发布。我必须用 c# 在 asp.net 中完成。有人有工作项目吗?需要一步一步的帮助。我尝试了几个项目,但都没有成功。我正在尝试的当前项目在第一次发布后返回 400 bad request 错误。 所以,我再说一遍,我需要一个不返回错误且不返回网站名称的工作项目, 谢谢, 阿德里安

【问题讨论】:

    标签: facebook publish facebook-wall


    【解决方案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 "";
    }
    

    【讨论】:

      【解决方案2】:

      我不知道是否有人为 asp 或 c# 编写了 Facebook API,但你不能只使用基本的 HTTP 请求吗?

      来自http://developers.facebook.com/docs/reference/api/

      “您可以通过使用访问令牌向适当的连接 URL 发出 HTTP POST 请求来发布到 Facebook 图表。”

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-29
        • 2012-07-08
        • 1970-01-01
        相关资源
        最近更新 更多