Skip to content

Instantly share code, notes, and snippets.

@inaz2
Last active December 27, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inaz2/7274619 to your computer and use it in GitHub Desktop.
Save inaz2/7274619 to your computer and use it in GitHub Desktop.
Facebookで特定のグループにいるfriendのリストを取得
<script>
// https://www.facebook.com/groups/$gid/
var gid = '$gid';
FB.api('/'+gid+'/members', function(v){
Log.info('/'+gid+'/members', v);
var members = v.data.map(function(v){return v.id});
FB.api('/me/friends', function(v){
Log.info('/me/friends', v);
var friends= v.data.map(function(v){return v.id});
var friends_in_group = members.filter(function(v){return friends.indexOf(v) !== -1});
Log.info('friends_in_group', friends_in_group.join(","));
});
});
</script>

FacebookのJavaScript Test Consoleから実行できる。

リストはカンマ区切りの文字列としてコンソールに出力される。 Graph API Explorerで下記のようにPOSTすることで、指定のfriendlistにまとめて追加できる。

// https://www.facebook.com/lists/$listid
POST /$listid/members
members=$friends_in_group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment