- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
自 3 天以来,我一直在尝试如何使用 C# 创建我的粉丝页面墙,我注意到两件事:- Facebook 提供未更新的文档,没有完整和糟糕的示例(api 经常更改)- Facebook 经常改变他的 api,很多帖子都过时了。有人可以更正我的代码或向我提供完整的好代码吗?
这是我的代码:
if (String.IsNullOrEmpty(Request.QueryString["code"]))
{
Response.Redirect("https://graph.facebook.com/oauth/authorize?client_id=157873644371673&redirect_uri=http://localhost:2551/Default.aspx&scope=publish_stream,manage_pages,offline_access&display=popup");
}
else
{
FacebookClient fb = new FacebookClient();
dynamic result1 = fb.Get("oauth/access_token", new
{
client_id = "MY_APP_ID",
client_secret = "MY_SECRET_ID",
grant_type = "client_credentials",
redirect_uri = "www.mysite.com"
});
fb.AppId = "MY_APP_ID";
fb.AppSecret = "MY_SECRET_ID";
fb.AccessToken = result1.access_token;
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.req_perms = "manages_pages";
parameters.scope = "manages_pages";
parameters.actions = new
{
name = "View on Zombo",
link = "www.zombo.com",
};
parameters.privacy = new
{
value = "ALL_FRIENDS",
};
try
{
var result = fb.Post("/" + "MY_FACEBOOK_FAN_PAGE_ID" + "/feed", parameters);
}
catch (FacebookOAuthException ex)
{
//handle something
Response.Write(ex.Message);
}
}
最佳答案
我希望这篇文章对很多人有帮助,我尽量简单明了:
1-创建您的 facebook 开发者帐户,并在您的计算机 (localhost
) 中测试您的代码,在“使用 facebook 身份验证的网站身份验证”字段中设置您的本地主机地址。对我来说,它将是 http://localhost:2551/Default.aspx
例如,因为我在我的 wweb 应用程序的 Defaut.aspx 中进行测试。当您在您的网站上部署时,您将更改此地址(对我来说,我将在将代码部署到我的网站之前更改为 http://www.mywebsiteurl.com/Default.aspx)。
2- 使用您的 Facebook 用户帐户,创建您的粉丝页面。
3-当你创建了你的粉丝专页后,去你的粉丝专页查看URL获取你的PAGE_ID例如我的是http://www.facebook.com/pages/toto/446533181408238?ref=ts&fref=ts所以我的 PAGE_ID 是 446533181408238
3- 快完成了,只是一点点解释:因为我创建了粉丝页面,我是粉丝页面的管理员,我必须请求 facebook 的授权才能发帖,因为我的开发者帐户所以我必须获得 2 个操作的授权: publish_stream 和 manage_pages。
让我们开始编码:
private void Do()
{
string app_id = "157873644371675";
string app_secret = "c27a10c347af4280720fa3d76c9ae08c";
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 = System.Net.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);
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.natiska.com/article.html";
parameters.picture = "http://www.natiska.com/dav.png";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
//446533181408238 is my fan page
client.Post("/446533181408238/feed", parameters);
}
}
关于c# - 如何使用 c# 和 asp.net 在我的页面粉丝墙上的 facebook 中发帖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15487184/
我的网站上有一个 Faceboon 粉丝 api,我想自己设置它的样式,但我似乎没有用。我确实将 CSS 设置为 ftp 上的 css 文件,但它就像风扇盒一样使用了它。 谁知道问题出在哪里? 风扇盒
我有一个博客 (wordpress) 和一个用于我博客的 facebook 粉丝页面(拥有超过 1 个粉丝!)。每次我在我的博客上发布内容时,我都想在我的 FB 墙上发布一条消息。最好是 PHP。 同
我在我的博客上使用官方粉丝框小部件有一段时间了,想用加载更少内容的缓存版本的小部件替换它。 小部件(适用于 Wordpress)运行良好 (http://www.electriceasel.com/p
我一直在尝试从我的一个业务页面中删除所有大约 5 万的关注者。我使用 Selenium Web 驱动程序和 Python 来废弃。 我能够获得关注者对话框,并且我能够滚动该对话框以加载更多关注者。然而
我是一名优秀的程序员,十分优秀!