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?

  • $\begingroup$ Oska, I don't see how that applies to a Group. isn't it just from friends? $\endgroup$
    – Mmm
    Mar 11 '14 at 17:00
  • $\begingroup$ Thanks Oska, got it all working in the end! works like a dream! $\endgroup$
    – Mmm
    Mar 11 '14 at 20:00
  • $\begingroup$ after a bit of digging it didn't work so still no solution :( $\endgroup$
    – Mmm
    Mar 13 '14 at 12:40
  • $\begingroup$ Apologies Oska, I forgot to tick it. Done now and I must say it is one hell of an answer! $\endgroup$
    – Mmm
    Apr 17 '14 at 21:28

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*)
      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]


    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 :)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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