2015-05-10 42 views
1

我用 https://developers.facebook.com/tools/access_token/我找帖子(牆臉譜)和我的朋友

我創建一個應用程序。我想得到我和我的朋友的牆的帖子。

我嘗試me/feedme/posts但我什麼也沒得到。

我有這個單元測試。

有什麼建議嗎?

[TestMethod] 
    public void Basic_using_SDK() 
    { 
     // http://blog.prabir.me/posts/facebook-csharp-sdk-making-requests 
     var fb = new Facebook.FacebookClient(); 

     var result = (IDictionary<string, object>)fb.Get("4"); 

     var id = (string)result["id"]; 
     var name = (string)result["name"]; 
     var firstName = (string)result["first_name"]; 
     var lastName = (string)result["last_name"]; 
     var link = (string)result["link"]; 
     var username = (string)result["username"]; 
     var gender = (string)result["gender"]; 
     var male = (string)result["locale"]; 


     var parameters = new Dictionary<string, object>(); 
     parameters["fields"] = "id,name"; 

     result = (IDictionary<string, object>)fb.Get("4", parameters); 
     id = (string)result["id"]; 
     name = (string)result["name"]; 


     dynamic result2 = fb.Get("4"); 

     id = result2.id; 
     name = result2.name; 
     firstName = result2.first_name; 
     lastName = result2.last_name; 
     link = result2.link; 
     username = result2.username; 
     gender = result2.gender; 
     male = result2.locale; 


     dynamic parameters2 = new ExpandoObject(); 
     parameters2.fields = "id,name"; 

     dynamic result3 = fb.Get("4", parameters); 
     id = result3.id; 
     name = result3.name; 

     dynamic me = fb.Get("zuck"); 
     firstName = me.first_name; 
     lastName = me.last_name; 


     var client = new FacebookClient(AccessToken); 
     dynamic me2 = client.Get("me"); 
     string aboutMe = me2.about; 

     dynamic result4 = client.Get("/me/feed"); 

     foreach (dynamic post in result4.data) 
     { 
      var fromName = post.from.name; 
      Console.WriteLine(fromName); 
     } 

     dynamic result5 = client.Get("/me/posts"); 
     for (int i = 0; i < result5.Count; i++) 
     { 
     } 


     // https://www.facebook.com/profile.php?id=xxxxxxx 
     // https://graph.facebook.com/xxxxxxx 
     var uidKiquenet = "xxxxx"; 
     var query = string.Format(@"SELECT status_id,message,time,source,uid,place_id 
          FROM status WHERE uid IN (SELECT uid FROM status WHERE uid = '" + uidKiquenet + "') ORDER BY time DESC"); 

     dynamic parameters6 = new ExpandoObject(); 
     parameters6.q = query; 

     dynamic results6 = fb.Get("/xxxxx?fields=id,name,age_range,about,email,first_name,gender"); 


     string myMessage = "Hello from Test"; 

     fb.PostTaskAsync("me/feed", new { message = myMessage }).ContinueWith(t => 
     { 
      if (!t.IsFaulted) 
      { 
       string message = "Great, your message has been posted to you wall!"; 
       Console.WriteLine(message); 
      } 
     }); 

     fb.GetTaskAsync("me").ContinueWith(t => 
     { 
      if (!t.IsFaulted) 
      { 
       var result11 = (IDictionary<string, object>)t.Result; 
       string myDetails = string.Format("Your name is: {0} {1} and your Facebook profile Url is: {3}", 
                (string)result11["first_name"], (string)result11["last_name"], 
                (string)result11["link"]); 
       Console.WriteLine(myDetails); 
      } 
     }); 

     // This uses Facebook Query Language 
     // See https://developers.facebook.com/docs/technical-guides/fql/ for more information. 
     query = string.Format("SELECT uid,name,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) ORDER BY name ASC", "me()"); 

     fb.GetTaskAsync("fql", new { q = query }).ContinueWith(t => 
     { 
      if (!t.IsFaulted) 
      { 
       var result1 = (IDictionary<string, object>)t.Result; 
       var data = (IList<object>)result1["data"]; 
       var count = data.Count; 
       var message = string.Format("You have {0} friends", count); 
       Console.WriteLine(message); 

       foreach (IDictionary<string, object> friend in data) 
        Console.WriteLine((string)friend["name"]); 
      } 
     }); 

    } 
+0

你知道,FQL被棄用,在新的應用程序不能正常工作了,對不對?無論如何,你是否使用具有正確權限的用戶訪問令牌? – luschn

+0

在審查狀態** https://developers.facebook.com/apps/xxxxx/review-status/**我的應用程序(在開發中)默認的權限是:***電子郵件,public_profile,user_friends *** – Kiquenet

+0

不知道爲什麼你想通過審查過程,雖然你的應用程序還沒有完成... – luschn

回答

1

您必須使用正確的權限授權才能訪問提要帖子。嘗試使用user_posts進行授權,如文檔中所述:https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed#read

請注意,除非您發佈在授權用戶的信息牆上,否則無法訪問朋友的帖子。

關於審閱,您可能需要閱讀此:https://developers.facebook.com/docs/facebook-login/review/faqs#what_is_review

順便說一句,FQL已被廢棄,只在2.0版應用程序的工作 - 而不是較新的。

1

同樣的事情發生在我身上。這是我的解決方案

我讓我的項目在Facebook開發者控制檯上註冊。然後我做了和你一樣的代碼,但無法獲得帖子/信息。過了一段時間,我將我的應用程序審查申請提交給了Facebook團隊(它仍處於開發早期階段),並且在他們的反饋之後,我得到了我的代碼工作。所以待審覈的應用程序也可能是您的問題。該選項在應用程序設置中可用。給它一個鏡頭

更新 另一個代碼示例是這裏

if (Request["code"] == null) 
      { 
       Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", 
        FB_app_id, Request.Url.AbsoluteUri, FB_scope)); 
       return 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}&perms=status_update" 
        , FB_app_id, Request.Url.AbsoluteUri, FB_scope, Request["code"].ToString(), FB_secret_id); 
       HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; 
       using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) 
       { 

        StreamReader rd = new StreamReader(response.GetResponseStream()); 

        string vals = rd.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"]; 
        Session["fb_access_token"] = access_token; 

        return true; 


       } 

      } 
+0

ASPX頁面中的示例,而不是單元測試?要求**迴應,請求**? – Kiquenet

+0

使用它們沒有問題,我使用cshtml文件而不是aspx文件 – ImranNaqvi

相關問題