Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am the admin of a Facebook group for our year at university and wanted to graph the members of the group like you can with your own friends so we can find the isolated people and get rid of them (as they are spamming). I have tried treating the page as an ID but don't really know how to proceed. Is this possible?

share|improve this question
    
See here. –  Öskå Mar 11 at 16:40
    
Oska, I don't see how that applies to a Group. isn't it just from friends? –  Max Mar 11 at 17:00
    
I assumed that what can be done with friends can also be done with a group. Maybe this can help. I don't own a FB group so I can't tell much.. –  Öskå Mar 11 at 18:16
    
Thanks Oska, got it all working in the end! works like a dream! –  Max Mar 11 at 20:00
    
Answer your own question? :) Did you use the link I gave you? Is it a duplicate? –  Öskå Mar 11 at 22:11

1 Answer 1

up vote 5 down vote accepted

CommunityGraphPlot@SocialMediaData["Facebook", "FriendNetwork"] only takes your friends and their mutual friends to group and link them, showing connections between each of them, and showing the isolated friends. Mathematica only allows you to analyze your own "FriendNetwork" via the token given by the Wolfram Mathematica Connection Facebook app.

Thus I see two ways to access the spammers in a Facebook group:

  1. Analyze the members and check you have "MutualFriends" with them.

  2. Analyze the feeds from a Facebook group and check whether you have "MutualFriends" with the most active users.

In both cases you will need a token given here.


Since I took the public StackOverFlow Facebook group I have no mutual friend with anyone and the "MutualFriend" filter doesn't filter anyone. With your group you should have matches.

The following shows that heavy spammers are caught anyway. If the spammer is someone (or something) with new Facebook IDs and new messages every time it gets more complicated.


  1. Inspired by the beginning of this you can do the following:

    groupID = "222005977818649";
    members = Import["https://graph.facebook.com/"<>groupID<>"/members?limit=1000&access_token=" 
                     <> token, "JSON"][[1]] //. Rule[x_, y_] :> y;
    
    memberids = members[[All, 2]];
    mutualfriends[id_] := Length@SocialMediaData[{"Facebook", id}, "MutualFriends"] /. {} :> {0}
    

    where mutualfriends /@ memberids returns a list with the number of mutual friends. Then the names of the isolated persons can be extracted with:

    Extract[members[[All, 3]], Position[mutualfriends /@ memberids, 0]]
    

    The main issue with this method is that it doesn't check if the member has been recently active or not, if he spams or not. Hence the following:

  2. Still inspired by the beginning of this you can do the following:

    rawfeeds = Import["https://graph.facebook.com/"<>groupID<>"/feed?limit=5000&access_token=" 
                      <> token, "JSON"][[1]] /. Rule[x_, y_] :> y;
    (* group Links, Pictures and messages under the same tag *)
    feeds = (rawfeeds //. {Rule[x_, y_] :> {x, y}, 
                           List["picture", x_] :> List["message", x], 
                           List["link", x_] :> List["message", x], 
                           List["caption", x_] :> List["message", x]});
    feeds = DeleteDuplicates[Flatten@#] & /@ GatherBy[#, First] & /@ feeds; 
    (*extract all interesting data*)
    rawIDsNames = Extract[feeds, Position[feeds, List["from", __]]];
    ids = (DeleteDuplicates@rawIDsNames)[[All, 3]];
    names = (DeleteDuplicates@rawIDsNames)[[All, 5]];
    messages = Column /@ Extract[feeds, Position[feeds, List["message", __]]][[All, 2 ;;]];
    (*definition of a few interesting functions*)
    getMessage[id_String] := Select[Thread[{rawIDsNames[[All, 3]], messages}], First@# == id &][[All,2]]
    getID[name_String] := Select[Thread[{ids, names}], Last@# == name &][[1, 1]]
    getName[id_String] := Select[Thread[{ids, names}], First@# == id &][[1, 2]]
    mutualfriends[id_] := Length@SocialMediaData[{"Facebook", id}, "MutualFriends"] /. {} :> {0}
    numberOfPosts[id_] := Length@getMessage@id
    (* filter the posts from the posters without mutual friends *)
    Print@"Extracting mutual friends..."
    unknownids = Extract[ids, Position[mutualfriends /@ ids, 0]];
    unknownnames = getName /@ unknownids;
    postsfromunknown = numberOfPosts /@ unknownids;
    Print@"Extracting pictures..."
    unknownpics = SocialMediaData[{"Facebook", #}, "Picture"] & /@ unknownids;
    (* use the above data *)
    activeusers = Select[Reverse@SortBy[Thread[{unknownids, unknownnames, unknownpics , postsfromunknown}], Last@# &], #[[4]] > 2 &];(*more than 2 posts*)
    
    PieChart[
      Table[Tooltip[activeusers[[i, 4]], activeusers[[i, 3]]], {i, 1, Length@activeusers}],
      ChartLabels -> Placed[{ToString /@ activeusers[[All, 2]], activeusers[[All, 4]]}, {"VerticalCallout", "RadialCenter"}],
      PlotRange -> All, ImageSize -> 500]
    

    PieChart

    Then if you want to check whether it really is spam or not you can check the messages by using getMessage@getID@name e.g.:

    getMessage@getID@"Leela Kiran"
    

    {what is the validation pattern [...], what is the validation pattern [...], etc.}


Note: if anyone has ideas in order to filter messages and define them as spam or if anyone has an idea on how Graph could be used here please let me know :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.