2015-05-19 301 views
1

經過相當的搜索後,我能夠在Facebook上發佈自己的信息。但我的目標是張貼在我管理頁面的頁面上。我做了一些更多的研究,並且能夠獲得我管理的頁面的訪問令牌。當我試圖職位上它,SDK給我的錯誤發佈到Facebook頁面作爲頁面

The user hasn't authorized the application to perform this action

這裏是我供你參考代碼:

 string app_id = "xxxxx"; 
     string app_secret = "yyyyyyy"; 
     string scope = "publish_actions,manage_pages"; 

     if (Request["code"] == null) 
     { 
      string url = string.Format(
       "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", 
       app_id, Request.Url.AbsoluteUri, scope); 
      Response.Redirect(url, false); 
     } 
     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 = System.Net.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); 

      dynamic parameters = new ExpandoObject(); 
      parameters.message = "Check out this funny article"; 
      parameters.link = "http://www.natiska.com/article.html"; 
      parameters.picture = "http://www.natiska.com/dav.png"; 
      parameters.name = "Article Title"; 
      parameters.caption = "Caption for the link"; 

      //zzzzzzz is my fan page 
      string pageAccessToken = ""; 
      JsonObject jsonResponse = client.Get("me/accounts") as JsonObject; 
      foreach (var account in (JsonArray)jsonResponse["data"]) 
      { 
       string accountName = (string)(((JsonObject)account)["name"]); 

       if (accountName == MY_PAGE_NAME) 
       { 
        pageAccessToken = (string)(((JsonObject)account)["access_token"]); 
        break; 
       } 
      } 

      client = new FacebookClient(pageAccessToken); 
      client.Post("/zzzzzzz/feed", parameters); 

回答

0

Facebook應用程序不到風度有manage_page & publish_page許可,而不是這個,你可以創建測試應用程序並從u可以爲您的測試創建測試用戶。 從那裏你可以管理所有的頁面帖子和數據。

相關問題