13/05/2011

[PHP, XML] Twitter friends graph

Brief example on how to create and draw some Twitter user’s friends graph.

Piccolo esempio di come creare e disegnare il grafo dei friends di un dato utente Twitter.

 

English:

With friends Twitter means “people whom the user follows”. Starting from a chosen user, we grab all his friends until a depth level of 3 and we create a XML file with a proper structure to be opened by Gephi in order to graphically visualize the result. The number of users we get is far lower than the real one due to Twitter API’s limitations.

To create the gexf file for Gephi, just run the HowDoYouGraph script after editing the $username variable with the desired username. After a little coffee break, in the same folder as the script you should find a file named grafo.gexf.

 

Show an example graph for user VivoMikiX and download the gexf source.

 

Stats about the undirected example graph:

  • Total nodes: 5013
  • Total edges: 5539
  • Medium degree = 2.21
  • Diameter = 6
  • Density = 0
  • Modularity = 0.876
    • Number of communities = 72
  • Weakly connected components = 1
  • Medium clustering coefficient = 0.014
    • Total triangles = 202
  • Eigenvector centrality with 300 iterations = 0.0325
  • Medium path length = 4.496
    • Number of shortest paths = 25125156
    • Radius = 3

 

Italiano:

Con friends si intendono tutte le persone che l'utente segue. Partendo da un dato utente, recuperiamo i suoi friends fino al livello 3 e generiamo un file XML con una struttura gradita a Gephi per visualizzare graficamente il risultato. Il numero di utenti recuperati e' inferiore al numero reale a causa di limitazioni imposte dalle API di Twitter.

Per creare il file gexf per Gephi, basta far girare lo script HowDoYouGraph dopo aver modificato la variabile $username con lo username desiderato. Dopo aver preso un caffe', nella stessa cartella dello script apparira' un file chiamato grafo.gexf che e' quello che ci interessa.

 

Visiona un grafo di esempio per l’utente VivoMikiX e scarica il file gexf sorgente.

 

Statistiche sul grafo d’esempio, considerandolo indiretto:

  • Totale nodi: 5013
  • Totale archi: 5539
  • Grado Medio = 2.21
  • Diametro = 6
  • Densità = 0
  • Modularità = 0.876
    • Numero di Comunità = 72
  • Componenti connesse debolmente = 1
  • Coefficiente di Clustering Medio = 0.014
    • Triangoli totali = 202
  • Centralità di autovettori con 300 iterazioni = 0.0325
  • Lunghezza cammino medio = 4.496
    • Numero di percorsi piu' corti = 25125156
    • Raggio = 3

No comments:

Post a Comment

With great power comes great responsibility