C# 如何使用 Facebook Developer Toolkit 在墙上发布内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1166229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I post something to a Wall using Facebook Developer Toolkit?
提问by jamesaharvey
Does anyone have experience using the Facebook Developer Toolkit? I am trying to post something to a Facebook user's Wall, but can't figure out how to use the API? Could someone could give me an example or point me to some documentation on the API's usage?
有没有人有使用 Facebook Developer Toolkit 的经验?我想在 Facebook 用户的墙上发布一些内容,但不知道如何使用 API?有人可以给我一个例子或指向我一些关于 API 使用的文档吗?
采纳答案by jamesaharvey
I actually found documentation and samples to do what I was looking for here: http://facebooktoolkit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28001
我实际上找到了文档和示例来做我在这里寻找的东西:http: //facebooktoolkit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28001
EDIT:
After initializing the Facebook session I called the Stream.Publish() method on the API.
编辑:
初始化 Facebook 会话后,我在 API 上调用了 Stream.Publish() 方法。
FacebookService.API.stream.publish(...);
回答by H789
Bit late, but maybe it still helps others: http://facebooktoolkit.codeplex.com/Thread/View.aspx?ThreadId=75412
有点晚了,但也许它仍然可以帮助其他人:http: //facebooktoolkit.codeplex.com/Thread/View.aspx?ThreadId=75412
回答by user1380934
I created a video tutorial showing how to do exactly this. Here is the link:
我创建了一个视频教程,展示了如何做到这一点。链接在这里:
http://www.markhagan.me/Samples/Grant-Access-And-Post-As-Facebook-User-ASPNet
http://www.markhagan.me/Samples/Grant-Access-And-Post-As-Facebook-User-ASPNet
And here is the code:
这是代码:
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" });
}
}
}
}