本文整理汇总了Golang中github.com/kurrik/twittergo.Tweet类的典型用法代码示例。如果您正苦于以下问题:Golang Tweet类的具体用法?Golang Tweet怎么用?Golang Tweet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tweet类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Notify
// Notify updates the authorized user's status. Returns the tweet ID on success.
func (n *Notifier) Notify(r *scuttlebutt.Repository) (*scuttlebutt.Message, error) {
text := NotifyText(r)
// Construct request.
req, err := http.NewRequest("POST", "/1.1/statuses/update.json", strings.NewReader((url.Values{"status": {text}}).Encode()))
if err != nil {
return nil, fmt.Errorf("notify request: %s", err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
// Send request.
resp, err := n.Client.SendRequest(req)
if err != nil {
return nil, fmt.Errorf("send request: %s", err)
}
defer resp.Body.Close()
// Parse the response.
var tweet twittergo.Tweet
if err := resp.Parse(&tweet); err != nil && strings.Contains(err.Error(), "Status is over 140 characters") {
return nil, ErrTweetTooLong
} else if err != nil {
return nil, fmt.Errorf("parse: %s", err)
}
// Update last tweet time cache.
n.lastTweetTime = tweet.CreatedAt()
return &scuttlebutt.Message{ID: tweet.Id(), Text: text, RepositoryID: r.ID}, nil
}
开发者ID:zchee,项目名称:scuttlebutt,代码行数:31,代码来源:notifier.go
示例2: main
func main() {
var (
err error
client *twittergo.Client
tweet *twittergo.Tweet
)
if client, err = LoadCredentials(); err != nil {
fmt.Printf("Could not parse CREDENTIALS file: %v\n", err)
os.Exit(1)
}
tweet_ids := []string{
"451453919017697280",
"451453883575848960",
"451453847622262784",
"451453811035357184",
"451453775882899456",
"451453738603909120",
"451453703375953920",
"451453667409817600",
"451453613231964160",
"451453567233040384",
"451453517819949056",
"451453478502539264",
"451453436769218560",
}
for _, id := range tweet_ids {
if tweet, err = GetTweet(client, id); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(tweet.Text())
}
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:34,代码来源:main.go
示例3: 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
示例4: 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
示例5: newChannelConverter
func newChannelConverter(c chan *Tweet, client *twittergo.Client) func([]byte) {
rateLimitActive := false
timer := time.AfterFunc(10*time.Second, func() {
rateLimitActive = false
})
timer.Stop()
return func(data []byte) {
if rateLimitActive {
return
}
rateLimitActive = true
timer.Reset(10 * time.Second)
var tweet twittergo.Tweet
err := json.Unmarshal(data, &tweet)
if err != nil {
log.Printf("Received invalid tweet: %s", err)
return
}
profileImageUrl, err := getUserProfileImageURL(client, tweet.User().Id())
if err != nil {
log.Printf("Could not get users profile image url: %s", err)
return
}
profileImage, err := getImage(profileImageUrl)
if err != nil {
log.Printf("Could not get users profile image: %s", err)
return
}
c <- &Tweet{
Text: tweet.Text(),
Date: tweet.CreatedAt(),
Author: TwitterUser{
ScreenName: tweet.User().ScreenName(),
Name: tweet.User().Name(),
ProfilePicture: profileImage,
},
}
}
}
开发者ID:voxelbrain,项目名称:pixelpixel,代码行数:43,代码来源:twitter.go
示例6: RespondToTweet
func (tw *RealTwitterWrapper) RespondToTweet(tweet *twittergo.Tweet, message string) {
var (
err error
user twittergo.User
req *http.Request
resp *twittergo.APIResponse
)
user = tweet.User()
data := url.Values{}
// set status
status := fmt.Sprintf("@%v %v", user.ScreenName(), message)
data.Set("status", status)
// set in_reply_to_status_id
status_id := fmt.Sprintf("%d", tweet.Id())
data.Set("in_reply_to_status_id", status_id)
log.Printf("Set status '%v' to '%v' in reply to %v", status, user.ScreenName(), status_id)
body := strings.NewReader(data.Encode())
req, err = http.NewRequest("POST", "/1.1/statuses/update.json", body)
if err != nil {
log.Fatalf("Could not parse request: %v\n", err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err = tw.client.SendRequest(req)
if err != nil {
log.Fatalf("Could not send request: %v\n", err)
}
tweet = &twittergo.Tweet{}
err = resp.Parse(tweet)
if err != nil {
log.Fatalf("Problem parsing response: %v\n", err)
}
}
开发者ID:joho,项目名称:goadventure,代码行数:36,代码来源:real_twitter_wrapper.go
示例7: RespondToTweet
func (tw *FakeTwitterWrapper) RespondToTweet(tweet *twittergo.Tweet, message string) {
fmt.Printf("Hypothetically Send tweet '%v' to '%v'\n", message, tweet.User().ScreenName())
}
开发者ID:joho,项目名称:goadventure,代码行数:3,代码来源:fake_twitter_wrapper.go
注:本文中的github.com/kurrik/twittergo.Tweet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论