张贴到Facebook -图API

本文关键字:API Facebook 张贴 | 更新日期: 2023-09-27 18:09:55

我已经成功地通过使用以下代码读取了我的Facebook帐户:

IAuthorizationState authorization = client.ProcessUserAuthorization();
            if (authorization == null)
            {
                // Kick off authorization request
                client.RequestUserAuthorization();
            }
            else
            {
                var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
                Session["access_token"] = authorization.AccessToken;
                using (var response = request.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        var graph = FacebookGraph.Deserialize(responseStream);
                        this.nameLabel.Text = HttpUtility.HtmlEncode(graph.Name);
                    }

                }
            }

我现在正试图发布到我的Facebook新闻feed,我正在努力找到一个指南来帮助我通过它。我试着自己启动它,但由于某种原因,它似乎抛出了一个400:Bad Request错误。

        var request = WebRequest.Create("https://graph.facebook.com/me/feed?");
        var postdata = "message=hello";
        postdata += "&access_token" + Session["access_token"].ToString();
        var data = Encoding.ASCII.GetBytes(postdata);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = data.Length;
        using (var stream = request.GetRequestStream())
        {
            stream.Write(data, 0, data.Length);
        }
        var response = (HttpWebResponse)request.GetResponse();
        var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

谁能帮助我理解为什么我的代码返回错误?

张贴到Facebook -图API

使用http://facebooksdk.net/简化您的工作。存储访问令牌并重用每个请求,直到它过期。