所以我在 facebook 上有一个应用程序,它有权发布_stream、manage_pages,到目前为止,我可以将“文本”更新发布到我自己的个人资料中,其中显示“通过应用程序名称”。
然后我试图代表页面从这个应用程序发布到我的页面。
我可以通过client.Post("/page name/feed", new { message = "abcd" });
(仅文本)来做到这一点,但如果我尝试发布链接、标题或图片,它仍然会发布在我的页面上,但我的个人资料就像我在该页面上共享某些内容一样,而不是作为我的页面发布.
我正在使用这种方法发布。
private void CheckAuthorization()
{
string app_id = "APP_ID";
string app_secret = "APP_SECRET";
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_tokens = tokens["access_token"];
var client = new FacebookClient(access_tokens);
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this New Item";
parameters.link = "https://www.example.com";
parameters.picture = "http://www.example.com/images/img.jpg";
parameters.name = "Item Title";
parameters.caption = "Caption for the link";
client.Post("/AllTheMed/feed", new { message = "lsjlsjlsjkldf" });
}
}