我能够通过Facebook应用程序和ASP.NET C#SDK将消息发布到我的墙上。我有一个永不过期的访问令牌,它工作到2011年7月25日。由于一些安全相关的原因,它被FB重置。所以我改变了我的代码,使用下面的代码动态获取访问令牌。
string url = "https://graph.facebook.com/oauth/access_token?client_id=app_id&client_secret=app_secret&grant_type=client_credentials&scope=offline_access,publish_stream";
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.ServicePoint.Expect100Continue = false;
webRequest.Timeout = 20000;
StreamReader responseReader = null;
if (webRequest.Method == "POST")
{
webRequest.ContentType = "application/x-www-form-urlencoded";
//POST the data.
requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(string.Empty);
responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
responseData = responseReader.ReadToEnd();
accessToken = responseData.Substring(responseData.IndexOf("=") + 1, responseData.Length - responseData.IndexOf("=") - 1);
}
我使用
执行发布 if (accessToken.Length > 0)
{
url = "https://graph.facebook.com/me/feed?access_token=" + accessToken;
}
var client = new FacebookClient();
dynamic parameters = new ExpandoObject();
if (!(String.IsNullOrEmpty(txtMessage.Text) & String.IsNullOrWhiteSpace(txtMessage.Text)))
{
parameters.message = txtMessage.Text;
}
parameters.link = "";
parameters.picture = "";
parameters.name = "";
parameters.caption = "";
parameters.description = "";
parameters.actions = new
{
name = "",
link = "",
};
parameters.privacy = new
{
value = "ALL_FRIENDS",
};
parameters.targeting = new
{
countries = "",
regions = "",
locales = "",
};
try
{
dynamic result = client.Post("me/feed", parameters);
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
我收到以下异常“(OAuthException)必须使用活动访问令牌来查询有关当前用户的信息。” 2011年7月25日之后发生了什么变化?
我搜索了很多内容以找到解决方案,但没有解决我的问题。
提前致谢! MANOOH