Csharp/C#教程:ASP.NET发布到Facebook Wall分享


ASP.NET发布到Facebook Wall

我试图发布到Facebook墙, 而不使用像C#Facebook SDK这样的API。 我正确地获取了访问令牌以及所有这些,但我使用以下代码禁止403:

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(); } 

你不应该发布curl -F …作为post请求的主体。 curl是一个命令行实用程序,允许您与http进行交互。 您想发布到https://graph.facebook.com/ {graphId} / feed?access_token = {token},其中postData为“message = This is a test”,用括号替换括号中的内容。

上述就是C#学习教程:ASP.NET发布到Facebook Wall分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/961055.html

(0)
上一篇 2021年11月25日
下一篇 2021年11月25日

精彩推荐