Examples changes (#201)

This commit is contained in:
Pedro Nasser
2016-11-01 18:15:27 -02:00
committed by C Cirello
parent 570fdea062
commit 5d9269e186
91 changed files with 967 additions and 424 deletions

View File

@@ -0,0 +1,58 @@
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
type payload struct {
Username string `json:"username"`
}
func main() {
username := "getiron"
// Getting username in payload
envPayload := os.Getenv("PAYLOAD")
if envPayload != "" {
var pl payload
err := json.Unmarshal([]byte(envPayload), &pl)
if err != nil {
log.Println("Invalid payload")
return
}
if pl.Username != "" {
username = pl.Username
}
}
fmt.Println("Looking for tweets of the account:", username)
// Twitter auth config
config := oauth1.NewConfig(os.Getenv("CONFIG_CUSTOMER_KEY"), os.Getenv("CONFIG_CUSTOMER_SECRET"))
token := oauth1.NewToken(os.Getenv("CONFIG_ACCESS_TOKEN"), os.Getenv("CONFIG_ACCESS_SECRET"))
httpClient := config.Client(oauth1.NoContext, token)
// Twitter client
client := twitter.NewClient(httpClient)
// Load tweets
tweets, _, err := client.Timelines.UserTimeline(&twitter.UserTimelineParams{ScreenName: username})
if err != nil {
fmt.Println("Error loading tweets: ", err)
}
// Show tweets
for _, tweet := range tweets {
fmt.Println(tweet.User.Name + ": " + tweet.Text)
}
}