• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang twittergo.APIResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/kurrik/twittergo.APIResponse的典型用法代码示例。如果您正苦于以下问题:Golang APIResponse类的具体用法?Golang APIResponse怎么用?Golang APIResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了APIResponse类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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


示例2: main

func main() {
	var (
		err     error
		client  *twittergo.Client
		req     *http.Request
		resp    *twittergo.APIResponse
		results *map[string]interface{}
	)
	client, err = LoadCredentials()
	if err != nil {
		fmt.Printf("Could not parse CREDENTIALS file: %v\n", err)
		os.Exit(1)
	}
	url := fmt.Sprintf("/1.1/application/rate_limit_status.json")
	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)
	}
	fmt.Printf("Response: %v\n", resp)
	//fmt.Printf("%v\n", resp.ReadBody())

	results = &map[string]interface{}{}
	if err = resp.Parse(results); err != nil {
		fmt.Printf("Could not parse results: %v\n", err)
		os.Exit(1)
	}
	PrintMap(*results)
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:34,代码来源:main.go


示例3: 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


示例4: parseWithErrorHandling

func parseWithErrorHandling(resp *twittergo.APIResponse, out interface{}) {
	err := resp.Parse(out)
	// TODO recover from 2013/04/28 14:16:32 Problem parsing response: Error 187: Status is a duplicate.
	if err != nil {
		log.Fatalf("Problem parsing response: %v\n", err)
	}
}
开发者ID:joho,项目名称:goadventure,代码行数:7,代码来源:real_twitter_wrapper.go


示例5: responseData

func (twComm *twitterComm) responseData(url string) ([]byte, error) {
	fmt.Println("Getting response for", url)
	var req *http.Request
	var err error
	if req, err = http.NewRequest("GET", url, nil); err != nil {
		fmt.Println("Error occured on creating request url", url, err)
		return nil, err
	}

	var resp *twittergo.APIResponse
	if resp, err = twComm.client.SendRequest(req); err != nil {
		fmt.Println("Error occured on sending request", url, err)
		return nil, err
	}
	defer resp.Body.Close()

	var body = []byte{}                                    //need to parse own response for JSON
	if body, err = ioutil.ReadAll(resp.Body); err != nil { //read all the data as []byte
		fmt.Println("Error in ioutil Reading of response", url, err)
		return nil, err
	}

	if strings.Contains(string(body), "Rate limit exceeded") {
		fmt.Println("---------------------------------------------")
		fmt.Println("URL: ", url)
		fmt.Printf("Rate limit:           %v\n", resp.RateLimit())
		fmt.Printf("Rate limit remaining: %v\n", resp.RateLimitRemaining())
		fmt.Printf("Rate limit reset:     %v\n---------------------------------------------\n", resp.RateLimitReset())
		twComm.handleRateLimit()
		return twComm.responseData(url)
	}

	return body, nil
}
开发者ID:Melinysh,项目名称:Project-Clay,代码行数:34,代码来源:TwitterComm.go


示例6: 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


示例7: 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


示例8: printResponseRateLimits

func printResponseRateLimits(resp *twittergo.APIResponse) {
	if resp.HasRateLimit() {
		log.Printf("Rate limit:           %v\n", resp.RateLimit())
		log.Printf("Rate limit remaining: %v\n", resp.RateLimitRemaining())
		log.Printf("Rate limit reset:     %v\n", resp.RateLimitReset())
	} else {
		log.Printf("Could not parse rate limit from response.\n")
	}
}
开发者ID:joho,项目名称:goadventure,代码行数:9,代码来源:real_twitter_wrapper.go


示例9: 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


示例10: 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


示例11: main

func main() {
	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", madTweet())
	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)
	}
}
开发者ID:dillonhafer,项目名称:mad-wisdom,代码行数:44,代码来源:main.go


示例12: GetTweet

func GetTweet(client *twittergo.Client, id string) (tweet *twittergo.Tweet, err error) {
	var (
		query = url.Values{"id": []string{id}}
		url   = fmt.Sprintf("/1.1/statuses/show.json?%v", query.Encode())
		req   *http.Request
		resp  *twittergo.APIResponse
	)
	if req, err = http.NewRequest("GET", url, nil); err != nil {
		err = fmt.Errorf("Could not parse request: %v\n", err)
		return
	}
	if resp, err = client.SendRequest(req); err != nil {
		err = fmt.Errorf("Could not send request: %v\n", err)
		return
	}
	tweet = &twittergo.Tweet{}
	if err = resp.Parse(tweet); err != nil {
		err = fmt.Errorf("There was an error: %v\n", err)
	}
	return
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:21,代码来源:main.go


示例13: fetchAndPrintList

func fetchAndPrintList(client *twittergo.Client, path string, query url.Values) (err error) {
	var (
		req     *http.Request
		resp    *twittergo.APIResponse
		results twittergo.Lists
	)
	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)
			return
		}
		resp, err = client.SendRequest(req)
		if err != nil {
			err = fmt.Errorf("Could not send request: %v\n", err)
			return
		}
		results = twittergo.Lists{}
		if err = resp.Parse(&results); err != nil {
			if err = handleRateLimit(err); err != nil {
				err = fmt.Errorf("Problem parsing response: %v\n", err)
				return
			} else {
				continue
			}
		}
		fmt.Printf("\n")
		for i, list := range results {
			fmt.Printf("%v.) ", i+1)
			printList(&list)
		}
		printRateLimit(resp)
		return
	}
	return
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:38,代码来源:main.go


示例14: 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


示例15: 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


示例16: 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


示例17: 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


示例18: Get

// Get is the generic method used to perform a call to the REST APIs
func (tw Twitter) Get(query Query, options *social.Options) (posts social.Posts, pages uint, err error) {
	var req *http.Request
	var resp *twittergo.APIResponse

	log.Debugln("Performing a request")

	// Init options
	if options == nil {
		log.Debugln("No option passed, using default ones")
		options = social.DefaultOptions()
	}
	if options.Paginate == false {
		options.MaxPages = 1
	}
	log.WithFields(options.ToFields()).Debugf("Options")

	// Init query
	query.Set("count", strconv.FormatUint(uint64(options.Count), 10))
	log.WithFields(query.ToFields()).Debugf("Query")

	posts = make(social.Posts, 0)
	for pages < options.MaxPages || options.MaxPages == 0 {

		// Create the URL
		url := fmt.Sprintf("/1.1/search/tweets.json?%v", query.Encode())
		// Create the HTTP Request
		req, err = http.NewRequest("GET", url, nil)
		if err != nil {
			return
		}
		// Send the Auth request
		resp, err = tw.api.SendRequest(req)
		if err != nil {
			return
		}
		// Increment the total number of pages retrieved
		pages++

		// Parse results
		var results = &twittergo.SearchResults{}
		err = resp.Parse(results)
		if err != nil {
			return
		}

		// Convert data to posts
		for _, tweet := range results.Statuses() {
			post, _ := tw.ToPost(tweet)
			posts = append(posts, post)
		}

		log.Debugf("Got page %d with %d tweets", pages, len(results.Statuses()))

		// Handle pagination, chack if a new page is needed
		values, nextQueryError := results.NextQuery()
		if nextQueryError != nil {
			log.Debug(nextQueryError)
			break
		}
		query = Query{values}
		log.WithFields(query.ToFields()).Debugf("New page query")
	}

	log.Debugf("Query ended, retrieved %d posts", len(posts))
	return
}
开发者ID:Volox,项目名称:GoSocialCrawler,代码行数:67,代码来源:twitter.go


示例19: getTweets

func getTweets() {
	var (
		err    error
		client *twittergo.Client
		req    *http.Request
		resp   *twittergo.APIResponse
		max_id uint64
		out    *os.File
		query  url.Values

		text []byte
	)
	if client, err = LoadCredentials(); err != nil {
		ERROR.Println("Could not parse CREDENTIALS file:", err)
		os.Exit(1)
	}
	if out, err = os.Create(TweetCacheFile); err != nil {
		ERROR.Println("Could not create output file:", TweetCacheFile)
		os.Exit(1)
	}
	defer out.Close()
	const (
		count   int = 100
		urltmpl     = "/1.1/statuses/user_timeline.json?%v"
		minwait     = time.Duration(10) * time.Second
	)
	query = url.Values{}
	query.Set("count", fmt.Sprintf("%v", count))
	query.Set("screen_name", ScreenName)
	total := 0

	if max_id != 0 {
		query.Set("max_id", fmt.Sprintf("%v", max_id))
	}
	endpoint := fmt.Sprintf(urltmpl, query.Encode())
	if req, err = http.NewRequest("GET", endpoint, nil); err != nil {
		ERROR.Println("Could not parse request:", err)
	}
	if resp, err = client.SendRequest(req); err != nil {
		ERROR.Println("Could not send request:", err)
	}

	results = &twittergo.Timeline{}
	if err = resp.Parse(results); err != nil {
		if rle, ok := err.(twittergo.RateLimitError); ok {
			dur := rle.Reset.Sub(time.Now()) + time.Second
			if dur < minwait {
				// Don't wait less than minwait.
				dur = minwait
			}
			WARNING.Println("Rate limited. Reset at", rle.Reset, "Waiting for", dur)
			time.Sleep(dur)

		} else {
			ERROR.Println("Problem parsing response:", err)
		}
	}
	batch := len(*results)
	if batch == 0 {
		INFO.Println("No more results, end of timeline.")
	} else {
		cache = results
	}
	for _, tweet := range *results {
		if text, err = json.Marshal(tweet); err != nil {
			ERROR.Println("Could not encode Tweet:", err)
			os.Exit(1)
		}
		out.Write(text)
		out.Write([]byte("\n"))
		max_id = tweet.Id() - 1
		total += 1
	}
	INFO.Println("Got", batch, "Tweets")
	if resp.HasRateLimit() {
		INFO.Println(resp.RateLimitRemaining(), " calls available")
	}

	INFO.Println("--------------------------------------------------------")
	INFO.Println("Wrote", total, "Tweets to", TweetCacheFile)
}
开发者ID:morriswinkler,项目名称:twitter_proxy,代码行数:81,代码来源:twitter.go



注:本文中的github.com/kurrik/twittergo.APIResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang twittergo.Client类代码示例发布时间:2022-05-23
下一篇:
Golang twittergo.NewClient函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap