【发布时间】:2017-08-06 18:46:09
【问题描述】:
我有一个运行计划作业的 Web 应用程序,该作业从我管理的页面中提取 Facebook 评论。这是一个sn-p
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 中。
谢谢
【问题讨论】:
标签: c# facebook facebook-graph-api access-token