Пример #1
0
//Init for Tumblr pkg
func init() {
	var err error
	config, err = common.ReadConfigFrom(configurationFilename)
	if err != nil {
		panic(err)
	}

	Log("Create tumblr client")

	appKey := config.Get("tumblr", "app_key")
	appSecret := config.Get("tumblr", "app_secret")
	oauthToken := config.Get("tumblr", "oauth_token")
	oauthTokenSecret := config.Get("tumblr", "oauth_token_secret")
	callbackURL := config.Get("tumblr", "url")

	client = gotumblr.NewTumblrRestClient(appKey, appSecret, oauthToken, oauthTokenSecret, callbackURL, "http://api.tumblr.com")
}
Пример #2
0
func (o *OauthConfig) FetchTumblrInfo() int64 {
	client := gotumblr.NewTumblrRestClient(
		o.AppKey,
		o.AppSecret,
		o.AccessToken,
		o.SecretToken,
		o.CallBackUrl,
		"http://api.tumblr.com")

	var optionParms = map[string]string{
		"limit":  "1",
		"offset": "10",
	}

	blogPhotoInfo := client.Posts("mirakui.tumblr.com", "photo", optionParms)
	log.Println("Total Posts:", blogPhotoInfo.Total_posts)
	return blogPhotoInfo.Total_posts
}
Пример #3
0
func (o *OauthConfig) FetchTumblrImageUrl() string {
	client := gotumblr.NewTumblrRestClient(
		o.AppKey,
		o.AppSecret,
		o.AccessToken,
		o.SecretToken,
		o.CallBackUrl,
		"http://api.tumblr.com")

	TotalPosts := o.FetchTumblrInfo()
	rand.Seed(time.Now().Unix())
	randOffset := rand.Int63n(TotalPosts)

	randOffsetStr := fmt.Sprint(randOffset)
	log.Println("rand offset:", randOffsetStr)

	var optionParms = map[string]string{
		"limit":  "1",
		"offset": randOffsetStr,
	}
	log.Println("options params:", optionParms)

	blogPhotoInfo := client.Posts("mirakui.tumblr.com", "photo", optionParms)

	var imageUrl string
	if len(blogPhotoInfo.Posts) != 0 {
		var base_phpto_post gotumblr.PhotoPost
		for i, _ := range blogPhotoInfo.Posts {
			json.Unmarshal(blogPhotoInfo.Posts[i], &base_phpto_post)
			imageUrl = base_phpto_post.Photos[0].Alt_sizes[0].Url
			log.Println(base_phpto_post.Photos[0].Alt_sizes[0].Url)
		}
	}

	return imageUrl
}
Пример #4
0
func (mod *TumblrBee) Run(eventChan chan bees.Event) {
	mod.client = gotumblr.NewTumblrRestClient(mod.consumerKey, mod.consumerSecret,
		mod.token, mod.tokenSecret,
		mod.callbackUrl, "http://api.tumblr.com")
}