C# 取得Facebook 朋友清單、說讚的內容清單

以下假設程式已登入FB並取得FacebookOAuthResult.AccessToken

接下來我要把FB的朋友列表中的ID和NAME放到Dictionary中

以下假設程式已登入FB並取得FacebookOAuthResult.AccessToken

接下來我要把FB的朋友列表中的ID和NAME放到Dictionary中

程式碼如下

 

Dictionary<string, object> result = new Dictionary<string,object>();
 
var fb = new FacebookClient(fbAuthRelt.AccessToken);
 
//取得朋友list
dynamic friends = fb.Get("/me/friends");
 
foreach (dynamic friend in friends.data)
{
         result.Add(friend.id, friend.name);
}
 
//取得說讚的內容list
Dictionary<string, object> result2 = new Dictionary<string,object>();
dynamic likes = fb.Get("/me/likes");
 
 foreach (dynamic like in likes.data)
 {
         result2.Add(like.id, like.name);
 }
 
 
網路上還有很多對 fb.Get 回傳的JASONObject 解析的方法,一樣可以達到類似結果
 
但上述方法是我覺得較簡單的!
 
希望對大家有用!