2012-02-07 63 views
-2

我正在WPF应用程序上工作,我想用facebook图形API检索新闻提要,所以我如何访问它也转换为序列化。如何使用Facebook Graph API检索新闻Feed。

谢谢。

+0

[你有什么试过吗?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – 2012-02-07 07:33:46

+0

我已经尝试使用图形API到Dictionary dic =新词典(); var temp = obj.GetObject(“1078733634_2931461360458”,dic);但难以显示数据。你能更形容吗? – 2012-02-07 07:50:04

回答

0

你会使用Facebook.dll U可以在Visual Studio中使用软件包管理器如果u使用C#例如

NuGet Package here..

和代码可能看起来像这样

public List<string> Facebook(string query) 
    { 
     // Facebook.FacebookAPI api = new FacebookAPI(); 

     List<string> list = new List<string>(); 
     string[] arr = new string[5]; 
     string result = null; 
     FacebookAPI api = new FacebookAPI(token); 
下载

//查询是您的搜索条件

 JSONObject q = api.Get("https://graph.facebook.com/search?q="+query+"&type=post"); 
     foreach (JSONObject item in q.Dictionary["data"].Array) 
     { 
      if (item.IsDictionary) 
      { 
       foreach (KeyValuePair<String,JSONObject> jso in item.Dictionary) 
       { 
        if (jso.Key == "message"/* || jso.Key == "name" || jso.Key == "description" || jso.Key == "link"*/) 
        { 
         for (int i = 0; i < 5; i++) 
         { 
          arr[i] = jso.Value.String; 

         } 
         list.Add (jso.Value.String); 

        } 
        else if (jso.Key == "likes") 
        { 
         foreach (JSONObject like in jso.Value.Dictionary["data"].Array) 
         { 
          foreach (KeyValuePair<String, JSONObject> lik in like.Dictionary) 
          { 
           if (lik.Key == "name") 
           { 
            result += lik.Value.String; 

           } 
           else if (lik.Key == "id") 
           { 
            result += lik.Value.String;  
           } 
          } 
         } 
         foreach (KeyValuePair<String, JSONObject> count in jso.Value.Dictionary) 
         { 
          if (count.Key == "count") 
          { 
           result += count.Value.String; 
          } 
         } 
        } 
        else if (jso.Key == "from") 
        { 
         foreach (KeyValuePair<String, JSONObject> froms in jso.Value.Dictionary) 
         { 
          if (froms.Key == "name") 
          { 
           result += froms.Value.String; 
          } 
         } 
        } 
       } 
      } 
      /* 
      else if (item.IsArray) 
      { 
       foreach (JSONObject j in item.Dictionary["data"].Array) 
       { 
        if (j.IsDictionary) 
        { 
         foreach (KeyValuePair<String,JSONObject> x in j.Dictionary) 
         { 
          result += (x.Key + " --- "+x.Value.String); 
         } 
        } 
       } 
      } 
      */ 
     } 
     return list; 
    } 

你当然可以改变后,并查询到任何你想要在Facebook的图形API

搜索和有另一种方式做到这一点使用FQL和其非常容易

希望会有所帮助。

+0

谢谢@Mido,但我想添加这个,但FacebookAPI给我错误我认为它不是在Facebook的DLL,但有没有任何地方,然后再次表明我感谢。我使用Facebook的DLL像这个版本Facebook的5.4 .1.0 – 2012-02-07 14:26:12

+0

你能告诉我你得到的错误吗? :) – Mido 2012-02-07 14:43:17

+0

非常感谢您的回答.. – 2012-02-10 12:19:32

相关问题