本文整理汇总了Golang中github.com/kurrik/twittergo.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetTimeline
func GetTimeline(client *twittergo.Client) (t *twittergo.Timeline, err error) {
var (
req *http.Request
resp *twittergo.APIResponse
rle twittergo.RateLimitError
ok bool
query url.Values
endpt string
)
query = url.Values{}
query.Set("count", fmt.Sprintf("%v", COUNT))
if client.User == nil {
// With a user token, the user_timeline.json method
// returns the current user. Without, you need to specify
// an explicit ID.
query.Set("screen_name", SCREEN_NAME)
}
endpt = fmt.Sprintf("/1.1/statuses/user_timeline.json?%v", query.Encode())
if req, err = http.NewRequest("GET", endpt, nil); err != nil {
return
}
if resp, err = client.SendRequest(req); err != nil {
return
}
t = &twittergo.Timeline{}
if err = resp.Parse(t); err != nil {
if rle, ok = err.(twittergo.RateLimitError); ok {
err = fmt.Errorf("Rate limited. Reset at %v", rle.Reset)
}
}
return
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:32,代码来源:app.go
示例2: SendMediaRequest
func SendMediaRequest(client *twittergo.Client, reqUrl string, params map[string]string, media []byte) (mediaResp twittergo.MediaResponse, err error) {
var (
req *http.Request
resp *twittergo.APIResponse
body io.ReadWriter = bytes.NewBufferString("")
mp *multipart.Writer
writer io.Writer
contentType string
)
mp = multipart.NewWriter(body)
for key, value := range params {
mp.WriteField(key, value)
}
if media != nil {
if writer, err = mp.CreateFormField("media"); err != nil {
return
}
writer.Write(media)
}
contentType = fmt.Sprintf("multipart/form-data;boundary=%v", mp.Boundary())
mp.Close()
if req, err = http.NewRequest("POST", reqUrl, body); err != nil {
return
}
req.Header.Set("Content-Type", contentType)
if resp, err = client.SendRequest(req); err != nil {
return
}
err = resp.Parse(&mediaResp)
return
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:31,代码来源:main.go
示例3: main
func main() {
var (
err error
client *twittergo.Client
req *http.Request
resp *twittergo.APIResponse
results *twittergo.SearchResults
)
client, err = LoadCredentials()
if err != nil {
fmt.Printf("Could not parse CREDENTIALS file: %v\n", err)
os.Exit(1)
}
query := url.Values{}
url := fmt.Sprintf("/1.1/statuses/home_timeline.json?%v", query.Encode())
req, err = http.NewRequest("GET", url, nil)
if err != nil {
fmt.Printf("Could not parse request: %v\n", err)
os.Exit(1)
}
resp, err = client.SendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
results = &twittergo.SearchResults{}
err = resp.Parse(results)
if err != nil {
fmt.Printf("There was an error: %v\n", err)
os.Exit(1)
}
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:32,代码来源:main.go
示例4: SendTweet
func SendTweet(username, message string) error {
var (
err error
client *twittergo.Client
req *http.Request
resp *twittergo.APIResponse
tweet *twittergo.Tweet
)
client = loadCredentials()
data := url.Values{}
data.Set("status", fmt.Sprintf("@%s %s", username, message)) //TODO: INSERT STUFF HERE!!!
body := strings.NewReader(data.Encode())
req, err = http.NewRequest("POST", "/1.1/statuses/update.json", body)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err = client.SendRequest(req)
if err != nil {
return err
}
tweet = &twittergo.Tweet{}
err = resp.Parse(tweet)
if err != nil {
return err
}
return nil
}
开发者ID:chdsbd,项目名称:wruff.xyz,代码行数:28,代码来源:tweet.go
示例5: sendTweet
func sendTweet(client *twittergo.Client, text string) {
var (
err error
req *http.Request
)
// Build Params
query := url.Values{}
query.Set("status", text)
// Bulid body
body := strings.NewReader(query.Encode())
// Prepare request
if req, err = http.NewRequest("POST", "/1.1/statuses/update.json", body); err != nil {
fmt.Printf("Could not parse request: %v\n", err)
os.Exit(1)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
// Send Request
if _, err = client.SendRequest(req); err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
}
开发者ID:etu,项目名称:TwitterHAL,代码行数:26,代码来源:TwitterHAL.go
示例6: sendTweet
func sendTweet(client *twittergo.Client, message string) {
data := url.Values{}
data.Set("status", message)
body := strings.NewReader(data.Encode())
req, err := http.NewRequest("POST", "/1.1/statuses/update.json", body)
if err != nil {
log.Printf("Could not parse request: %v", err)
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.SendRequest(req)
if err != nil {
log.Printf("Could not send request: %v", err)
return
}
tweet := &twittergo.Tweet{}
err = resp.Parse(tweet)
if err != nil {
if rle, ok := err.(twittergo.RateLimitError); ok {
log.Printf("Rate limited, reset at %v\n", rle.Reset)
} else if errs, ok := err.(twittergo.Errors); ok {
for i, val := range errs.Errors() {
log.Printf("Error #%v - ", i+1)
log.Printf("Code: %v ", val.Code())
log.Printf("Msg: %v\n", val.Message())
}
} else {
log.Printf("Problem parsing response: %v\n", err)
}
}
}
开发者ID:kienhung,项目名称:gohome,代码行数:31,代码来源:main.go
示例7: Tweet
func Tweet(newTweet string) {
var (
err error
client *twittergo.Client
req *http.Request
resp *twittergo.APIResponse
tweet *twittergo.Tweet
)
fmt.Println("Loading credentials ...")
client, err = LoadCredentials()
if err != nil {
fmt.Printf("Could not parse CREDENTIALS file: %v\n", err)
panic(err)
}
data := url.Values{}
data.Set("status", newTweet)
body := strings.NewReader(data.Encode())
req, err = http.NewRequest("POST", "/1.1/statuses/update.json", body)
if err != nil {
fmt.Printf("Could not parse request: %v\n", err)
os.Exit(1)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err = client.SendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
tweet = &twittergo.Tweet{}
err = resp.Parse(tweet)
if err != nil {
if rle, ok := err.(twittergo.RateLimitError); ok {
fmt.Printf("Rate limited, reset at %v\n", rle.Reset)
} else if errs, ok := err.(twittergo.Errors); ok {
for i, val := range errs.Errors() {
fmt.Printf("Error #%v - ", i+1)
fmt.Printf("Code: %v ", val.Code())
fmt.Printf("Msg: %v\n", val.Message())
}
} else {
fmt.Printf("Problem parsing response: %v\n", err)
}
os.Exit(1)
}
fmt.Printf("ID: %v\n", tweet.Id())
fmt.Printf("Tweet: %v\n", tweet.Text())
fmt.Printf("User: %v\n", tweet.User().Name())
if resp.HasRateLimit() {
fmt.Printf("Rate limit: %v\n", resp.RateLimit())
fmt.Printf("Rate limit remaining: %v\n", resp.RateLimitRemaining())
fmt.Printf("Rate limit reset: %v\n", resp.RateLimitReset())
} else {
fmt.Printf("Could not parse rate limit from response.\n")
}
}
开发者ID:lafisrap,项目名称:21tweet,代码行数:58,代码来源:tweeter.go
示例8: main
func main() {
// Register command-line flags.
numWords := flag.Int("words", 17, "maximum number of words to print")
prefixLen := flag.Int("prefix", 2, "prefix length in words")
flag.Parse() // Parse command-line flags.
rand.Seed(time.Now().UnixNano()) // Seed the random number generator.
c := NewChain(*prefixLen) // Initialize a new Chain.
c.Build(os.Stdin) // Build chains from standard input.
text := c.Generate(*numWords) // Generate text.
var (
err error
client *twittergo.Client
req *http.Request
resp *twittergo.APIResponse
tweet *twittergo.Tweet
)
client, err = LoadCredentials()
if err != nil {
fmt.Printf("Could not parse CREDENTIALS file: %v\n", err)
os.Exit(1)
}
data := url.Values{}
data.Set("status", text)
body := strings.NewReader(data.Encode())
req, err = http.NewRequest("POST", "/1.1/statuses/update.json", body)
if err != nil {
fmt.Printf("Could not parse request: %v\n", err)
os.Exit(1)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err = client.SendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
tweet = &twittergo.Tweet{}
err = resp.Parse(tweet)
if err != nil {
if rle, ok := err.(twittergo.RateLimitError); ok {
fmt.Printf("Rate limited, reset at %v\n", rle.Reset)
} else if errs, ok := err.(twittergo.Errors); ok {
for i, val := range errs.Errors() {
fmt.Printf("Error #%v - ", i+1)
fmt.Printf("Code: %v ", val.Code())
fmt.Printf("Msg: %v\n", val.Message())
}
} else {
fmt.Printf("Problem parsing response: %v\n", err)
}
os.Exit(1)
}
fmt.Printf("ID: %v\n", tweet.Id())
fmt.Printf("Tweet: %v\n", tweet.Text())
}
开发者ID:carriercomm,项目名称:cyborgmanifesto,代码行数:57,代码来源:borgia.go
示例9: GetTweets
// Gets tweets from max_id backwards.
// max_id==0 means latest tweet.
func GetTweets(client *twittergo.Client, user string, max_id uint64, since_id uint64) (tweets []map[string]interface{}, err error) {
args := url.Values{
"screen_name": []string{user},
"trim_user": []string{"true"},
"include_rts": []string{"true"},
"include_entities": []string{"true"},
"count": []string{"200"},
}
if max_id != 0 {
args["max_id"] = []string{strconv.FormatUint(max_id, 10)}
}
if since_id != 0 {
args["since_id"] = []string{strconv.FormatUint(since_id, 10)}
}
query := args.Encode()
url := "https://api.twitter.com/1.1/statuses/user_timeline.json?" + query
var req *http.Request
req, err = http.NewRequest("GET", url, nil)
if err != nil {
return
}
log.Printf("Fetching url %v\n", url)
r, err := client.SendRequest(req)
if err != nil {
return
}
ctype := r.Header.Get("Content-Type")
mtype, params, err := mime.ParseMediaType(ctype)
if mtype != "application/json" {
log.Printf("Response is not JSON: %q", ctype)
return
}
charset, ok := params["charset"]
if ok && charset != "utf-8" {
log.Printf("JSON has to be UTF-8: %q", ctype)
return
}
//TODO ponder rate-limiting http headers
//X-Ratelimit-Remaining: 143
//X-Ratelimit-Limit: 150
//X-Ratelimit-Reset: 1303182615
buf, err := ioutil.ReadAll(r.Body)
if err != nil {
return
}
err = r.Body.Close()
if err != nil {
return
}
err = json.Unmarshal(buf, &tweets)
return
}
开发者ID:darshandzend,项目名称:chivchiv,代码行数:57,代码来源:chivchiv.go
示例10: main
func main() {
var (
err error
client *twittergo.Client
req *http.Request
resp *twittergo.APIResponse
results *twittergo.SearchResults
)
client, err = LoadCredentials()
if err != nil {
fmt.Printf("Could not parse account.yaml file: %v\n", err)
os.Exit(1)
}
if len(os.Args) < 2 {
fmt.Printf("need args\n")
os.Exit(1)
}
query := url.Values{}
query.Set("q", os.Args[1])
url := fmt.Sprintf("/1.1/search/tweets.json?%v", query.Encode())
req, err = http.NewRequest("GET", url, nil)
if err != nil {
fmt.Printf("Could not parse request: %v\n", err)
os.Exit(1)
}
resp, err = client.SendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
results = &twittergo.SearchResults{}
err = resp.Parse(results)
if err != nil {
fmt.Printf("Problem parsing response: %v\n", err)
os.Exit(1)
}
for i, tweet := range results.Statuses() {
user := tweet.User()
fmt.Printf("%v.) %v\n", i+1, tweet.Text())
fmt.Printf("From %v (@%v) ", user.Name(), user.ScreenName())
fmt.Printf("at %v\n\n", tweet.CreatedAt().Format(time.RFC1123))
}
if resp.HasRateLimit() {
fmt.Printf("Rate limit: %v\n", resp.RateLimit())
fmt.Printf("Rate limit remaining: %v\n", resp.RateLimitRemaining())
fmt.Printf("Rate limit reset: %v\n", resp.RateLimitReset())
} else {
fmt.Printf("Could not parse rate limit from response.\n")
}
}
开发者ID:blueskywalker,项目名称:GoLang,代码行数:54,代码来源:find.go
示例11: tweetMessage
func tweetMessage(message string, client *twittergo.Client) error {
data := url.Values{}
data.Set("status", message)
body := strings.NewReader(data.Encode())
req, err := http.NewRequest("POST", "/1.1/statuses/update.json", body)
if noError(err) {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
_, err = client.SendRequest(req)
}
return err
}
开发者ID:nplatt,项目名称:tldrtweet,代码行数:11,代码来源:tldrtweet.go
示例12: main
func main() {
var (
err error
client *twittergo.Client
req *http.Request
resp *twittergo.APIResponse
customTweet *CustomTweet
)
client, err = LoadCredentials()
if err != nil {
fmt.Printf("Could not parse CREDENTIALS file: %v\n", err)
os.Exit(1)
}
query := url.Values{}
query.Set("id", "641727937201311744") // https://twitter.com/kurrik/status/641727937201311744
url := fmt.Sprintf("%v?%v", "/1.1/statuses/show.json", query.Encode())
req, err = http.NewRequest("GET", url, nil)
if err != nil {
fmt.Printf("Could not parse request: %v\n", err)
os.Exit(1)
}
resp, err = client.SendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
customTweet = &CustomTweet{}
err = resp.Parse(customTweet)
if err != nil {
if rle, ok := err.(twittergo.RateLimitError); ok {
fmt.Printf("Rate limited, reset at %v\n", rle.Reset)
} else if errs, ok := err.(twittergo.Errors); ok {
for i, val := range errs.Errors() {
fmt.Printf("Error #%v - ", i+1)
fmt.Printf("Code: %v ", val.Code())
fmt.Printf("Msg: %v\n", val.Message())
}
} else {
fmt.Printf("Problem parsing response: %v\n", err)
}
os.Exit(1)
}
fmt.Printf("ID: %v\n", customTweet.CustomID)
fmt.Printf("Tweet: %v\n", customTweet.CustomText)
if resp.HasRateLimit() {
fmt.Printf("Rate limit: %v\n", resp.RateLimit())
fmt.Printf("Rate limit remaining: %v\n", resp.RateLimitRemaining())
fmt.Printf("Rate limit reset: %v\n", resp.RateLimitReset())
} else {
fmt.Printf("Could not parse rate limit from response.\n")
}
}
开发者ID:kurrik,项目名称:twittergo-examples,代码行数:53,代码来源:main.go
示例13: fetchNewTweets
func fetchNewTweets(client *twittergo.Client, lastTweet uint64) []twittergo.Tweet {
var (
err error
req *http.Request
resp *twittergo.APIResponse
results *twittergo.SearchResults
)
// Build search
query := url.Values{}
query.Set("q", "#svpol -rt")
query.Set("lang", "sv")
query.Set("result_type", "recent")
query.Set("count", "20")
query.Set("since_id", fmt.Sprintf("%d", lastTweet))
// Build URI
url := fmt.Sprintf("/1.1/search/tweets.json?%v", query.Encode())
// Prepare request
if req, err = http.NewRequest("GET", url, nil); err != nil {
fmt.Printf("Could not parse request: %v\n", err)
os.Exit(1)
}
// Sign and send request
if resp, err = client.SendRequest(req); err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
// Parse requests
results = &twittergo.SearchResults{}
if err = resp.Parse(results); err != nil {
fmt.Printf("Problem parsing response: %v\n", err)
os.Exit(1)
}
// Print ratelimit data
if resp.HasRateLimit() {
fmt.Printf("Rate limit: %v\n", resp.RateLimit())
fmt.Printf("Rate limit remaining: %v\n", resp.RateLimitRemaining())
fmt.Printf("Rate limit reset: %v\n", resp.RateLimitReset())
}
return results.Statuses()
}
开发者ID:etu,项目名称:TwitterHAL,代码行数:47,代码来源:TwitterHAL.go
示例14: SendApiRequest
func SendApiRequest(client *twittergo.Client, reqUrl string, params map[string]string) (resp *twittergo.APIResponse, err error) {
var (
body io.Reader
data url.Values = url.Values{}
req *http.Request
)
for key, value := range params {
data.Set(key, value)
}
body = strings.NewReader(data.Encode())
if req, err = http.NewRequest("POST", reqUrl, body); err != nil {
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err = client.SendRequest(req)
return
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:17,代码来源:main.go
示例15: Connect
func Connect(client *twittergo.Client, path string, query url.Values) (resp *twittergo.APIResponse, err error) {
var (
req *http.Request
)
url := fmt.Sprintf("https://stream.twitter.com%v?%v", path, query.Encode())
req, err = http.NewRequest("GET", url, nil)
if err != nil {
err = fmt.Errorf("Could not parse request: %v\n", err)
return
}
resp, err = client.SendRequest(req)
if err != nil {
err = fmt.Errorf("Could not send request: %v\n", err)
return
}
return
}
开发者ID:james-portman,项目名称:go-twitter-stream,代码行数:17,代码来源:stream.go
示例16: twitter
func twitter(command *bot.Cmd, matches []string) (msg string, err error) {
var (
client *twittergo.Client
query url.Values
req *http.Request
resp *twittergo.APIResponse
results *twittergo.Timeline
output string
)
if client, err = LoadCredentials(); err != nil {
return "Twitter | Could not get tweet", nil
}
query = url.Values{}
query.Set("count", "1")
query.Set("exclude_replies", "true")
query.Set("screen_name", matches[1])
endpoint := fmt.Sprintf("/1.1/statuses/user_timeline.json?%v", query.Encode())
if req, err = http.NewRequest("GET", endpoint, nil); err != nil {
return "Twitter | Could not get tweet", nil
}
if resp, err = client.SendRequest(req); err != nil {
return "Twitter | Could not get tweet", nil
}
results = &twittergo.Timeline{}
resp.Parse(results)
for _, tweet := range *results {
if _, err = json.Marshal(tweet); err != nil {
return "Twitter | Could not get tweet", nil
}
reg := regexp.MustCompile("\\s+")
text := reg.ReplaceAllString(tweet.Text(), " ") // Strip tabs and newlines
output = fmt.Sprintf("Twitter | %s (@%s) | %s | %s",
tweet.User().Name(),
tweet.User().ScreenName(),
text,
Time(tweet.CreatedAt()))
}
return output, nil
}
开发者ID:0x263b,项目名称:Porygon2,代码行数:45,代码来源:twitter.go
示例17: fetchAndPrintCursoredList
func fetchAndPrintCursoredList(client *twittergo.Client, path string, query url.Values) (err error) {
var (
req *http.Request
resp *twittergo.APIResponse
results twittergo.CursoredLists
i int64
)
i = 1
query.Set("cursor", "-1")
for {
url := fmt.Sprintf("%v?%v", path, query.Encode())
req, err = http.NewRequest("GET", url, nil)
req.Header.Set("Accept-Encoding", "gzip, deflate")
if err != nil {
err = fmt.Errorf("Could not parse request: %v\n", err)
break
}
resp, err = client.SendRequest(req)
if err != nil {
err = fmt.Errorf("Could not send request: %v\n", err)
break
}
results = twittergo.CursoredLists{}
if err = resp.Parse(&results); err != nil {
if err = handleRateLimit(err); err != nil {
err = fmt.Errorf("Problem parsing response: %v\n", err)
break
} else {
continue
}
}
fmt.Printf("\n")
for _, list := range results.Lists() {
fmt.Printf("%v.) ", i)
printList(&list)
i += 1
}
printRateLimit(resp)
if results.NextCursorStr() == "0" {
break
}
query.Set("cursor", results.NextCursorStr())
}
return
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:45,代码来源:main.go
示例18: getUserProfileImageURL
func getUserProfileImageURL(client *twittergo.Client, userId uint64) (string, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.twitter.com/1.1/users/show.json?user_id=%d", userId), nil)
if err != nil {
return "", err
}
resp, err := client.SendRequest(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
var u user
err = json.NewDecoder(resp.Body).Decode(&u)
if err != nil {
return "", err
}
return u.ProfileImageUrl, nil
}
开发者ID:voxelbrain,项目名称:pixelpixel,代码行数:19,代码来源:twitter.go
示例19: postTweet
func postTweet(status string) error {
var (
err error
client *twittergo.Client
req *http.Request
resp *twittergo.APIResponse
tweet *twittergo.Tweet
)
client, err = LoadCredentials()
if err != nil {
fmt.Printf("Could not parse CREDENTIALS file: %v\n", err)
os.Exit(1)
}
data := url.Values{}
data.Set("status", status)
body := strings.NewReader(data.Encode())
req, err = http.NewRequest("POST", "/1.1/statuses/update.json", body)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err = client.SendRequest(req)
if err != nil {
return err
}
tweet = &twittergo.Tweet{}
err = resp.Parse(tweet)
if err != nil {
if rle, ok := err.(twittergo.RateLimitError); ok {
fmt.Printf("Rate limited, reset at %v\n", rle.Reset)
} else if errs, ok := err.(twittergo.Errors); ok {
for i, val := range errs.Errors() {
fmt.Printf("Error #%v - ", i+1)
fmt.Printf("Code: %v ", val.Code())
fmt.Printf("Msg: %v\n", val.Message())
}
} else {
fmt.Printf("Problem parsing response: %v\n", err)
}
}
return err
}
开发者ID:postfix,项目名称:markovmickens,代码行数:42,代码来源:markov.go
示例20: Tweet
func Tweet(client *twittergo.Client, post string) (*twittergo.Tweet, error) {
data := url.Values{}
data.Set("status", post)
body := strings.NewReader(data.Encode())
req, err := http.NewRequest("POST", "/1.1/statuses/update.json", body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.SendRequest(req)
if err != nil {
return nil, err
}
tweet := &twittergo.Tweet{}
err = resp.Parse(tweet)
if err != nil {
return nil, err
}
return tweet, nil
}
开发者ID:hugozhu,项目名称:weibo2twitter,代码行数:20,代码来源:twitter.go
注:本文中的github.com/kurrik/twittergo.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论