本文整理匯總了Golang中github.com/mrjones/oauth.Consumer類的典型用法代碼示例。如果您正苦於以下問題:Golang Consumer類的具體用法?Golang Consumer怎麽用?Golang Consumer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Consumer類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FetchTimelinePage
func FetchTimelinePage(c *oauth.Consumer, accessToken *oauth.AccessToken, page int) (tweets []interface{}, err error) {
resp, err := c.Get(
*flagURL,
map[string]string{
"skip_user": "1",
"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
}
示例2: favorite
// お気に入り
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
}
示例3: tweet
// ツイート
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
}
示例4: retweet
// リツイート
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
}
示例5: NewClientWithToken
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
}
示例6: NewClientWithToken
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}
}
示例7: GetFromAPI
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)
}
示例8: MakeClient
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)
}
示例9: token
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
}
示例10: Tumblr
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
}