牌語備忘録 -pygo

あくまでもメモです。なるべくオフィシャルの情報を参照してください。

牌語備忘録 -pygo

go でツイートを search/tweets api で取ってみるメモ

(go version go1.5.1 darwin/amd64)

ライブラリ

anaconda
A Go client library for the Twitter 1.1 API

$ go get github.com/ChimeraCoder/anaconda

コード

package main

import (
    "fmt"
    "github.com/ChimeraCoder/anaconda"
    "net/url"
)

const (
    consumerKey = "your consumerKey"
    consumerSecret = "your consumerSecret"
    accessToken = "your accessToken"
    accessTokenSecret = "your accessTokenSecret"
)

func main() {
    anaconda.SetConsumerKey(consumerKey)
    anaconda.SetConsumerSecret(consumerSecret)
    api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)

    v := url.Values{}
    v.Set("count", "10")
    searchResult, _ := api.GetSearch("#golang", v)
    for _, tweet := range searchResult.Statuses {
        fmt.Printf("[%s] %s\n", tweet.CreatedAt, tweet.Text)
    }
}

参考