C# 如何使用Facebook开发者工具包将内容发布到墙上?
有没有人有使用Facebook开发者工具包的经验?我试图在Facebook用户的墙上发布一些东西,但不知道如何使用API?有人能给我举个例子或者给我指一些关于API使用的文档吗?我实际上找到了一些文档和示例来完成我在这里寻找的工作: 编辑:C# 如何使用Facebook开发者工具包将内容发布到墙上?,c#,.net,facebook,C#,.net,Facebook,有没有人有使用Facebook开发者工具包的经验?我试图在Facebook用户的墙上发布一些东西,但不知道如何使用API?有人能给我举个例子或者给我指一些关于API使用的文档吗?我实际上找到了一些文档和示例来完成我在这里寻找的工作: 编辑: 初始化Facebook会话后,我在API上调用了Stream.Publish()方法 FacebookService.API.stream.publish(...); 虽然有点晚了,但也许这对其他人还是有帮助的:我制作了一个视频教程,展示了如何做到这一点。
初始化Facebook会话后,我在API上调用了Stream.Publish()方法
FacebookService.API.stream.publish(...);
虽然有点晚了,但也许这对其他人还是有帮助的:我制作了一个视频教程,展示了如何做到这一点。以下是链接: 代码如下:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
namespace FBO
{
public partial class facebooksync : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CheckAuthorization();
}
private void CheckAuthorization()
{
string app_id = "374961455917802";
string app_secret = "9153b340ee604f7917fd57c7ab08b3fa";
string scope = "publish_stream,manage_pages";
if (Request["code"] == null)
{
Response.Redirect(string.Format(
"https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
app_id, Request.Url.AbsoluteUri, scope));
}
else
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string vals = reader.ReadToEnd();
foreach (string token in vals.Split('&'))
{
//meh.aspx?token1=steve&token2=jake&...
tokens.Add(token.Substring(0, token.IndexOf("=")),
token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
string access_token = tokens["access_token"];
var client = new FacebookClient(access_token);
client.Post("/me/feed", new { message = "markhagan.me video tutorial" });
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
Net系统;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用Facebook;
命名空间FBO
{
公共部分类facebooksync:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
检查授权();
}
私有无效检查授权()
{
字符串app_id=“374961455917802”;
字符串app_secret=“9153b340ee604f7917fd57c7ab08b3fa”;
string scope=“发布\u流,管理\u页面”;
如果(请求[“代码”]==null)
{
重定向(string.Format(
"https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}“,
app_id,Request.Url.AbsoluteUri,scope));
}
其他的
{
字典标记=新字典();
字符串url=string.Format(“https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}”,
app_id,Request.Url.AbsoluteUri,作用域,Request[“code”]。ToString(),app_secret);
HttpWebRequest-request=WebRequest.Create(url)为HttpWebRequest;
使用(HttpWebResponse=request.GetResponse()作为HttpWebResponse)
{
StreamReader=新的StreamReader(response.GetResponseStream());
字符串vals=reader.ReadToEnd();
foreach(vals.Split('&')中的字符串标记)
{
//meh.aspx?token1=steve&token2=jake&。。。
tokens.Add(token.Substring(0,token.IndexOf(“=”)),
子字符串(token.IndexOf(“=”)+1,token.Length-token.IndexOf(“=”-1));
}
}
字符串访问令牌=令牌[“访问令牌”];
var client=新的FacebookClient(访问令牌);
client.Post(“/me/feed”,new{message=“markhagan.me视频教程”});
}
}
}
}
对于任何启动新应用程序的人,您可能会在这里得到更好的回复。您可能想在Codeplex上或在我一直在摆弄新3.0版本的网站上查看新的Facebook C#SDK。我无法连接。你能发布一些你的连接代码吗?