【问题标题】:How to upload image on facebook using graph api?如何使用图形 api 在 facebook 上上传图像?
【发布时间】:2012-11-24 18:56:58
【问题描述】:

我想在用户个人资料上上传一张图片。我有一张Bitmap 格式的图片。我正在使用此代码...

        Bitmap bit = new Bitmap("E:\\abc.jpg");
        MemoryStream ms = new MemoryStream();

        bit.Save(ms, ImageFormat.Jpeg);

        byte[] buffer = ms.ToArray();


        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://graph.facebook.com/me/photos?access_token=" + acc_token);

        req.Method = "POST";
        req.ContentLength = buffer.Length;
        //req.ContentType = "application/x-www-form-urlencoded";
        req.ContentType = "image/jpeg";                       

        Stream rq_strm = req.GetRequestStream();
        rq_strm.Write(buffer, 0, buffer.Length);
        rq_strm.Close();

        HttpWebResponse res = (HttpWebResponse)req.GetResponse();     //got error here
        Response.Write("RESPONSE: " + res.StatusDescription);

我收到了错误The remote server returned an error: (400) Bad Request. 我哪里错了?

【问题讨论】:

标签: c# asp.net facebook-graph-api facebook-c#-sdk


【解决方案1】:

基本上,这意味着服务器无法识别您的请求。通常对于 API,这意味着 API 无法破译某些内容,或者它缺少一个重要功能。在这种情况下,它确定您没有包含 source 标记。通常,这是通过带有 <input type='file'> 标签的 HTML 表单发送的。模拟这个的方法相当复杂,但this question 会为您指明正确的方向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2014-02-02
    • 2013-07-21
    • 2016-03-27
    相关资源
    最近更新 更多