2017-03-15 177 views
-1

我有一個web應用程序,它運行一個計劃作業,該作業從我管理的頁面中獲取Facebook評論。這裏是一個片段Facebook訪問令牌持續過期c#

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中。

感謝

回答