LoginSignup
11
6

More than 5 years have passed since last update.

Goでツイートしてみよう

Last updated at Posted at 2016-10-05

自己紹介

じゅんじゅんというニックネームで、関西を拠点に活動しているフロントエンドエンジニアです。

HAL大阪の2回生です👍 (2016.10.4現在)

よくstart up系イベントに行くので、大阪らへんの方は会いましょう!

GolangでTwitter

使うものは、Aditya Mukerjeeさんのanacondaというライブラリを使います。

コードを書いていくヨ

package main

import (
  "fmt"
  "github.com/ChimeraCoder/anaconda"
  "log"
)

func main() {
  anaconda.SetConsumerKey("[ck]")
  anaconda.SetConsumerSecret("[cs]")
  api := anaconda.NewTwitterApi("[at]", "[as]")

  text := "Hello from Golang."
  tweet, err := api.PostTweet(text, nil)
  if(err != nil){
    log.Fatal(err)
  }
  fmt.Println(tweet.Text)
}

Goはそれほど書いたことはないんですが、まぁ普通な流れですね。

anacondaを使っているところで認証周りをしてもらって、textにつぶやく内容を代入します。

PostTweet()を使いtwitterへつぶやいて、エラーがあればエラーの内容を表示し、

つぶやいた内容を標準出力するまでです。

最後に

main関数があるのは、やはり便利ですねぇ〜

Twitter -> @konojunya

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6