【发布时间】:2014-10-08 23:52:20
【问题描述】:
现在我正在从我的私人帐户和我的 页。我正在尝试让页面自己发布我的消息 创建的。我一直在阅读有关页面令牌的 som 文档。但 发现很难找到一些eksampels。你们有谁 知道将消息作为页面发布的下一步吗?将是 非常感谢
public void CheckAutorization()
{
string app_Id = "my_app_id";
string app_secret = "my_secret_id";
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 = 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);
var myAccount = client.Get("/me/accounts");
dynamic parameters = new ExpandoObject();
parameters.message = "test message";
parameters.link = "http://www.facebook.com";
parameters.picture = "http://www.fabric.co.uk/wp-content/uploads/2014/06/Facebook-teen-usage.jpg";
parameters.name = "facebook.fo";
parameters.caption = "test caption";
client.Post("/mypageUrl/feed", parameters);
}
}
【问题讨论】:
-
publish_stream 已弃用,而 publish_actions 涵盖了您已经需要的一切。使用权限时,请始终确保只请求您真正需要的权限。
-
感谢您的提示...您对我的页面问题有解决方案吗??
标签: facebook facebook-graph-api access-token