twitter api

API KEY発行

以下からアプリを作成
https://apps.twitter.com/

投稿

package twitter

import (
    "log"
    "net/http"
    "os"

    "github.com/ChimeraCoder/anaconda"
    "github.com/joho/godotenv"
    "google.golang.org/appengine"
    "google.golang.org/appengine/urlfetch"
)

func init() {
    err := godotenv.Load("key.env")
    if err != nil {
        log.Fatal("Error loading .env file")
    }
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    ctx := appengine.NewContext(r)
    anaconda.SetConsumerKey(os.Getenv("CONSUMER_KEY"))
    anaconda.SetConsumerSecret(os.Getenv("CONSUMER_SECRET"))
    api := anaconda.NewTwitterApi(os.Getenv("ACCESS_TOKEN"), os.Getenv("ACCESS_TOKEN_SECRET"))
    api.HttpClient.Transport = &urlfetch.Transport{Context: ctx}

    // values := url.Values{}
    _, err := api.PostTweet("hello!!", nil)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
    }
}

参考

http://www.apps-gcp.com/gae-go-twitter-bot-2/