Example #1
0
func FetchTimelinePage(c *oauth.Consumer, accessToken *oauth.AccessToken, page int) (tweets []interface{}, err error) {
	resp, err := c.Get(
		*flagURL,
		map[string]string{
			"skip_user":   "******",
			"count":       "100",
			"include_rts": "1",
			"page":        strconv.FormatInt(int64(page), 10),
		},
		accessToken,
	)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	tweets = make([]interface{}, 0)
	err = json.NewDecoder(resp.Body).Decode(&tweets)
	if err != nil {
		return nil, err
	}
	return tweets, nil
}
Example #2
0
// お気に入り
func favorite(queue Queue, client *oauth.Consumer, accessToken *oauth.AccessToken) error {
	_, err := client.PostForm(
		"https://api.twitter.com/1.1/favorites/create.json",
		map[string]string{"id": queue.TweetId},
		accessToken,
	)
	return err
}
Example #3
0
// ツイート
func tweet(queue Queue, client *oauth.Consumer, accessToken *oauth.AccessToken) error {
	_, err := client.PostForm(
		"https://api.twitter.com/1.1/statuses/update.json",
		map[string]string{"status": queue.Text},
		accessToken,
	)
	return err
}
Example #4
0
// リツイート
func retweet(queue Queue, client *oauth.Consumer, accessToken *oauth.AccessToken) error {
	_, err := client.PostForm(
		fmt.Sprintf("https://api.twitter.com/1.1/statuses/retweet/%s.json", queue.TweetId),
		nil,
		accessToken,
	)
	return err
}
Example #5
0
File: client.go Project: Ablu/drone
func NewClientWithToken(Consumer *oauth.Consumer, AccessToken string) *http.Client {
	var token oauth.AccessToken
	token.Token = AccessToken
	client, err := Consumer.MakeHttpClient(&token)
	if err != nil {
		log.Error(err)
	}
	return client
}
Example #6
0
func NewClientWithToken(url string, consumer *oauth.Consumer, AccessToken string) *Client {
	var token oauth.AccessToken
	token.Token = AccessToken
	client, err := consumer.MakeHttpClient(&token)
	if err != nil {
		log.Error(err)
	}
	return &Client{client, url, AccessToken}
}
Example #7
0
func (user *TwUser) GetFromAPI(c *oauth.Consumer, at *oauth.AccessToken) os.Error {
	response, err := c.Get(
		TW_URL_VERIFY_CREDENTIAL,
		map[string]string{"skip_status": "true"},
		at)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	return user.Get(response.Body)
}
Example #8
0
func (tl *TwTimeLine) GetFromAPI(c *oauth.Consumer, at *oauth.AccessToken, count int, sinceId string) os.Error {
	params := map[string]string{"include_entities": "true", "count": strconv.Itoa(count)}
	if sinceId != "" && sinceId != "0" {
		params["since_id"] = sinceId
	}
	response, err := c.Get(
		TW_URL_HOME_TIMELINE,
		params,
		at)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	return tl.Get(response.Body)
}
Example #9
0
File: client.go Project: ifo/trelgo
func MakeClient(consumer *oauth.Consumer, accessToken *oauth.AccessToken) (*http.Client, error) {
	if accessToken == nil && accessTokenCache == nil {
		return nil, fmt.Errorf("MakeClient failed - no oauth.AccessToken")
	}
	if accessToken == nil {
		accessToken = accessTokenCache
	}
	if consumer == nil && consumerCache == nil {
		return nil, fmt.Errorf("MakeClient failed - no consumer")
	}
	if consumer == nil {
		consumer = consumerCache
	}
	return consumer.MakeHttpClient(accessToken)
}
Example #10
0
func token(c *oauth.Consumer) *oauth.AccessToken {
	atoken := saved()
	if atoken != nil {
		return atoken
	}
	token, login, err := c.GetRequestTokenAndUrl("")
	ck(err)
	println(login)
	print("Hit enter when authorized...")
	_, err = os.Stdin.Read([]byte{0})
	ck(err)
	atoken, err = c.AuthorizeToken(token, "")
	ck(err)
	save(atoken)
	return atoken
}
Example #11
0
func Tumblr(f File, ch chan File) {
	tumbUri, _ := url.Parse(tumbHost)
	p := f.Url.Path
	if len(p) == 0 || p == "/" {
		tok, err := OAuth()
		if err != nil {
			f.SendErr(ch, &err)
			return
		}
		cons := oauth.Consumer{HttpClient: HClient}
		for i := 0; ; i += 20 {
			resp, err := cons.Get(tumbHost+tumbFollowing,
				map[string]string{"offset": strconv.Itoa(i)}, tok)
			check(err)
			var fr followingResponse
			checkResponse(resp, &fr)
			for _, b := range fr.Blogs {
				bUri, err := url.Parse(b.Url)
				check(err)
				bUri.Path = bUri.Host
				ch <- File{Url: *bUri}
			}
			if i >= fr.Total_blogs {
				break
			}
		}
	} else {
		tok, _, err := Keychain(*tumbUri)
		if err != nil {
			f.SendErr(ch, &err)
			return
		}
		err = tumblrBlog(f, tok, ch)
		f.SendErr(ch, &err)
	}
	return
}