Skip to content

JohnCoene/go-graphtweets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Go Report Card

go-graphtweets

Build Twitter networks.

go-graphtweets is the sister of the graphTweets R package.

Install

Install go-twitter

go get github.com/dghubble/go-twitter/twitter

Install go-graphtweets

go get github.com/JohnCoene/go-graphtweets/graphtweets

Documentation

The documentation is on godoc

Example

Set up go-twitter session.

// get tweets with go-twitter
config := oauth1.NewConfig("consumerKey", "consumerSecret")
token := oauth1.NewToken("accessToken", "accessSecret")
httpClient := config.Client(oauth1.NoContext, token)

// Twitter client
client := twitter.NewClient(httpClient)

// Search Tweets
search, _, _ := client.Search.Tweets(&twitter.SearchTweetParams{
  Query: "#golang",
})

Build graphs.

mentionsGraph := graphtweets.GetMentionsGraph(*search) // build mentions graph
retweetGraph := graphtweets.GetRetweetGraph(*search) // build retweet graph
hashtagGraph := graphtweets.GetHashtagGraph(*search) // build hashtag graph

Convert either graphs to wide.

wide := graphtweets.ToWide(&mentionsGraph)

Wide format is generally better/closer to the typical JSON.

serialized,_ := json.Marshal(wide)

fmt.Println(string(serialized))