ASP.NET发布到Facebook墙 [英] ASP.NET Post to Facebook Wall

查看:143
本文介绍了ASP.NET发布到Facebook墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图张贴到Facebook涂鸦墙,使用API​​,如C#的Facebook SDK。我得到正确的访问令牌和所有这一切,但我发现了一个禁止使用403以下code:

 保护串postToWall()
{
    VAR的accessToken =会话[_ FB_ACCESS_TOKEN];
    VAR graphId =会话[_ FB_USER_GRAPH_ID];    VAR URL =的String.Format(
        https://graph.facebook.com/{0}/feed
        graphId
    );    VAR REQ = WebRequest.Create(URL);
    req.Method =POST;
    req.Co​​ntentType =应用/的X WWW的形式urlen codeD;    字符串POSTDATA =的String.Format(
        @卷曲-F'ACCESS_TOKEN = {0}-F的消息=这是一个测试......https://graph.facebook.com/{1}/feed
        的accessToken,
        graphId
    );    字节[]的字节数组= Encoding.UTF8.GetBytes(POSTDATA);
    VAR流= req.GetRequestStream();
    stream.Write(字节数组,0,byteArray.Length);
    stream.Close();    WebResponse的响应= req.GetResponse();
    Console.WriteLine(((HttpWebResponse)响应).StatusDescription);
    流= response.GetResponseStream();
    StreamReader的读者=新的StreamReader(流);    返回reader.ReadToEnd();
}


解决方案

您不应张贴卷曲-F ......作为POST请求的主体。卷曲是一个命令行工具,使您可以以http交互。你想发布到 https://graph.facebook.com/ {} graphId /供稿?=的access_token {}令牌与 POSTDATA 是消息=这是一个测试,在与他们的价值观括号替换的东西。

I'm trying to post to a facebook wall, without using an API such as the C# Facebook SDK. I'm correctly getting the access token and all that, but I'm getting a 403 forbidden using the following code:

protected string postToWall()
{
    var accessToken = Session["_FB_ACCESS_TOKEN"];
    var graphId = Session["_FB_USER_GRAPH_ID"];

    var url = string.Format(
        "https://graph.facebook.com/{0}/feed",
        graphId
    );

    var req = WebRequest.Create(url);
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";

    string postData = string.Format(
        @"curl -F 'access_token={0}' -F 'message=This is a test...' https://graph.facebook.com/{1}/feed",
        accessToken,
        graphId
    );

    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    var stream = req.GetRequestStream();
    stream.Write(byteArray, 0, byteArray.Length);
    stream.Close();

    WebResponse response = req.GetResponse();
    Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    stream = response.GetResponseStream();
    StreamReader reader = new StreamReader(stream);

    return reader.ReadToEnd();
}

解决方案

You shouldn't be posting curl -F... as the body of the post request. curl is a command line utility that allows you to interact with http. You want to post to an https://graph.facebook.com/{graphId}/feed?access_token={token} with the postData being "message=This is a test" replacing things in brackets with their values.

这篇关于ASP.NET发布到Facebook墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆