我有一个运行计划工作的Web应用程序,它从我管理的页面中提取Facebook评论。这是一个片段
public void Execute(IJobExecutionContext context)
{
//get api details from the web.config
var pageId = WebConfigurationManager.AppSettings["FacebookPageId"];
var token = WebConfigurationManager.AppSettings["FacebookAPIToken"];
if (!string.IsNullOrEmpty(token))
{
//create a facebook client object
var client = new FacebookClient(token);
//make a call to facebook to retrieve the json data
dynamic graphJson = client.Get(pageId + "?fields=ratings{review_text,reviewer,rating}").ToString();
//deserialize the json returned from facebook
ReviewDeserializeData reviews = JsonConvert.DeserializeObject<ReviewDeserializeData>(graphJson);
//loop through the deserialized data and pass each review to the import class
foreach (var rating in reviews.ratings.data)
{
var fbRating = new FacebookRating
{
RatingReviewerId = long.Parse(rating.reviewer.id),
StarRating = rating.rating,
ReviewerName = rating.reviewer.name,
ReviewText = rating.review_text
};
ImportFacebookRating.ImportTheFacebookRating(fbRating);
}
}
}
这在页面访问令牌过期之前效果很好。我曾尝试过很多文章,例如这篇文章https://medium.com/@Jenananthan/how-to-create-non-expiry-facebook-page-token-6505c642d0b1#.24vb5pyiv,但我没有运气修复令牌过期。
有没有人知道我是如何实现这一点的,或者如果现有的令牌已经过期,是否有办法以编程方式生成新令牌?目前我把它作为应用程序设置存储在web.config中。
谢谢
答案 0 :(得分:1)
我在这里找到了答案,并且能够生成一个“永不”过期的令牌Long-lasting FB access-token for server to pull FB page info