我想用c#和Facebook sdk在我的Facebook页面上发帖。我可以在我的Facebook页面上发布内容,但其他人无法正常看到。即使是页面的管理员也只能查看帖子的标题,但无法查看该帖子的图片或内容。但是页面的管理员可以通过点击“>”查看帖子的内容这个标志旁边的帖子到页面。请指导我为什么会这样,我该如何解决这个问题。
protected void Page_Load(object sender, EventArgs e)
{
CheckAuthorization();
}
private void CheckAuthorization()
{
string app_id = "My App ID";
string app_secret = "My App Secret";
string scope = "publish_stream, publish_actions";
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('&'))
{
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 = "Hello This Is My First Post To Facebook";
parameters.link = "http://www.google.com";
parameters.picture = "http://www.mywebsite.com/picture/welcome.jpg";
parameters.name = "Hello Users We welcome you all";
parameters.caption = "Posted By Ashish";
client.Post("/My Facebook Page ID/feed", parameters);
}
}
请在我在几个网站上关注某些帖子之后第一次尝试这个时,请指导我做错的地方。
答案 0 :(得分:1)
您正在使用用户访问令牌向网页发布供稿。因此,Feed代表用户(而非页面)发布,这些内容在时间轴上显示为摘要。
如果您代表页面管理员本身发布了Feed(以便帖子在时间轴上正常显示),则需要使用具有publish_actions
权限的页面访问令牌。
要获取网页访问令牌,您需要使用具有/<page-id>?fields=access_token
权限的普通用户令牌查询:manage_pages
。
答案 1 :(得分:0)
我只是想补充说,有时你的应用程序在MODE:开发人员,所以你所做的一切只有开发人员可见,这实际上是我遇到的问题,所以你需要去你的应用程序仪表板并寻找类似“评论”的内容 [我讨厌给出确切的路径,因为Facebook每隔一段时间就改变一切] ,并寻找类似的东西:您的应用正在开发中,无法向公众开放,将其公开