Skip to content

Instantly share code, notes, and snippets.

@sugyan
Created August 20, 2018 03:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sugyan/7df17e63664f5250c2f54cabf652215b to your computer and use it in GitHub Desktop.
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"strings"
"golang.org/x/oauth2/clientcredentials"
)
// {Country:Japan CountryCode:JP Name:Kitakyushu PlaceType:{Code:7 Name:Town} WOEID:1110809}
// {Country:Japan CountryCode:JP Name:Saitama PlaceType:{Code:7 Name:Town} WOEID:1116753}
// {Country:Japan CountryCode:JP Name:Chiba PlaceType:{Code:7 Name:Town} WOEID:1117034}
// {Country:Japan CountryCode:JP Name:Fukuoka PlaceType:{Code:7 Name:Town} WOEID:1117099}
// {Country:Japan CountryCode:JP Name:Hamamatsu PlaceType:{Code:7 Name:Town} WOEID:1117155}
// {Country:Japan CountryCode:JP Name:Hiroshima PlaceType:{Code:7 Name:Town} WOEID:1117227}
// {Country:Japan CountryCode:JP Name:Kawasaki PlaceType:{Code:7 Name:Town} WOEID:1117502}
// {Country:Japan CountryCode:JP Name:Kobe PlaceType:{Code:7 Name:Town} WOEID:1117545}
// {Country:Japan CountryCode:JP Name:Kumamoto PlaceType:{Code:7 Name:Town} WOEID:1117605}
// {Country:Japan CountryCode:JP Name:Nagoya PlaceType:{Code:7 Name:Town} WOEID:1117817}
// {Country:Japan CountryCode:JP Name:Niigata PlaceType:{Code:7 Name:Town} WOEID:1117881}
// {Country:Japan CountryCode:JP Name:Sagamihara PlaceType:{Code:7 Name:Town} WOEID:1118072}
// {Country:Japan CountryCode:JP Name:Sapporo PlaceType:{Code:7 Name:Town} WOEID:1118108}
// {Country:Japan CountryCode:JP Name:Sendai PlaceType:{Code:7 Name:Town} WOEID:1118129}
// {Country:Japan CountryCode:JP Name:Takamatsu PlaceType:{Code:7 Name:Town} WOEID:1118285}
// {Country:Japan CountryCode:JP Name:Tokyo PlaceType:{Code:7 Name:Town} WOEID:1118370}
// {Country:Japan CountryCode:JP Name:Yokohama PlaceType:{Code:7 Name:Town} WOEID:1118550}
// {Country:Japan CountryCode:JP Name:Okinawa PlaceType:{Code:7 Name:Town} WOEID:2345896}
// {Country:Japan CountryCode:JP Name:Osaka PlaceType:{Code:7 Name:Town} WOEID:15015370}
// {Country:Japan CountryCode:JP Name:Kyoto PlaceType:{Code:7 Name:Town} WOEID:15015372}
// {Country:Japan CountryCode:JP Name:Japan PlaceType:{Code:12 Name:Country} WOEID:23424856}
// {Country:Japan CountryCode:JP Name:Okayama PlaceType:{Code:7 Name:Town} WOEID:90036018}
func main() {
config := &clientcredentials.Config{
ClientID: "*************************",
ClientSecret: "**************************************************",
TokenURL: "https://api.twitter.com/oauth2/token",
}
client := config.Client(context.Background())
res, err := client.Get("https://api.twitter.com/1.1/trends/place.json?id=23424856")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
type trend struct {
Name string `json:"name"`
TweetVolume int `json:"tweet_volume"`
}
var response []struct {
Trends []trend `json:"trends"`
}
if err := json.NewDecoder(res.Body).Decode(&response); err != nil {
log.Fatal(err)
}
words := []string{}
for _, t := range response[0].Trends {
if t.TweetVolume > 0 {
words = append(words, fmt.Sprintf("「%s」(%d件)", t.Name, t.TweetVolume))
}
}
fmt.Printf("現在のトレンドは %s です\n", strings.Join(words, "、"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment