🪶 thin

Very thin Twitter API client

thin is a Twitter library made by Go that supports Twitter API v1.1. It is designed to have fewer functions than the library has.

Since thin does not have Json parsing function, you need to parse Json by yourself. gjson is recommended for Json parser.

🚀 Install

go get github.com/Comamoca/thin

❓ How to use

package main

import (
	"github.com/Comamoca/thin"
	"github.com/tidwall/gjson"
)

func main(){
	// Set Keys
	keys := ApiKeys{os.Getenv("CONSUMER_KEY"),
		os.Getenv("CONSUMER_SECRET"),
		os.Getenv("ACCESS_TOKEN"),
		os.Getenv("ACCESS_TOKEN_SECRET")}

	// get client
	client := thin.Auth(keys)

	// Set query
	v := url.Values{}
	v.Set("q", "#golang")

	// Twitter API endpoint
	endp := "https://api.twitter.com/1.1/search/tweets.json?"

	tu := ThinUrl{url, v}
	// Generate URL
	url, _ := GenerateUrl(url)

	tweets, _ := client.Get(url)
	for _, tweet := range gjson.Get(res, "statuses").Array() {
			fmt.Println(gjson.Get(tweet.String(), "text"))
			fmt.Println("---------------------")
	}

}

👀 See the Exsamples

🍪 Types

thin.Keys

type ApiKeys struct {
	ConsumerKey    string
	ConsumerSecret string

	AccessToken       string
	AccessTokenSecret string
}

thin.ThinUrl

type ThinUrl struct {
	RawUrl string
	Value  url.Values
}

thin.Client

type Client struct {
  client *http.Client
}

🧩 Functions

Auth

func (keys ApiKeys) Auth() Client

Authenticate based on thin.ApiKey.

GenerateUrl

func GenerateUrl(tu ThinUrl) (string, error)

Generates a parsed URL based on thin.ThinUrl. This is useful when specifying parameters.

Get

func (clt Client) Get (url string) (string, error)

Execute a Get request based on the URL.

💡 Source of ideas

RubyでTwitter API v2を叩けるgemをつくりました

GitHub

View Github