當前位置: 首頁>>代碼示例>>Golang>>正文


Golang twittergo.NewClient函數代碼示例

本文整理匯總了Golang中github.com/kurrik/twittergo.NewClient函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewClient函數的具體用法?Golang NewClient怎麽用?Golang NewClient使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewClient函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Hashtags

// Hashtags returns a channel over which tweets can be received, which match
// at least one of the given hashtags.
func Hashtags(cred *Credentials, Hashtags ...string) (<-chan *Tweet, error) {
	c := make(chan *Tweet)
	restclient := twittergo.NewClient(&oauth1a.ClientConfig{
		ConsumerKey:    cred.ConsumerKey,
		ConsumerSecret: cred.ConsumerSecret,
	}, &oauth1a.UserConfig{
		AccessTokenKey:    cred.AccessToken,
		AccessTokenSecret: cred.AccessSecret,
	})

	httpstream.OauthCon = &oauth.OAuthConsumer{
		ConsumerKey:    cred.ConsumerKey,
		ConsumerSecret: cred.ConsumerSecret,
	}
	streamclient := httpstream.NewOAuthClient(&oauth.AccessToken{
		Token:  cred.AccessToken,
		Secret: cred.AccessSecret,
	}, newChannelConverter(c, restclient))

	err := streamclient.Filter(nil, Hashtags, nil, nil, false, nil)
	if err != nil {
		close(c)
	}
	return c, err
}
開發者ID:voxelbrain,項目名稱:pixelpixel,代碼行數:27,代碼來源:twitter.go

示例2: Connect

// Connect initializes a connection via Twitter API.
func Connect() *twittergo.Client {
	config := &oauth1a.ClientConfig{
		ConsumerKey:    Key,
		ConsumerSecret: Secret,
	}
	return twittergo.NewClient(config, nil)
}
開發者ID:gowroc,項目名稱:meetups,代碼行數:8,代碼來源:twitter.go

示例3: GetCredentials

func GetCredentials(config *Config) (client *twittergo.Client) {
	oc := &oauth1a.ClientConfig{
		ConsumerKey:    config.OAuth.Key,
		ConsumerSecret: config.OAuth.Secret,
	}
	return twittergo.NewClient(oc, nil)
}
開發者ID:tv42,項目名稱:twackup,代碼行數:7,代碼來源:config.go

示例4: LoadCredentials

func LoadCredentials() (client *twittergo.Client, err error) {
	credentials, err := ioutil.ReadFile("account.yaml")
	if err != nil {
		fmt.Println("There is no account.yaml")
		return nil, err
	}

	m := make(map[interface{}]interface{})

	err = yaml.Unmarshal([]byte(credentials), &m)

	if err != nil {
		log.Fatalf("error: %v", err)
	}

	twitter := m["twitter"].(map[interface{}]interface{})

	//fmt.Printf("%v\n", twitter)
	fmt.Printf("[%v]\n", twitter["consumerKey"])
	fmt.Printf("[%v]\n", twitter["consumerSecret"])
	fmt.Printf("[%v]\n", twitter["accessToken"])
	fmt.Printf("[%v]\n", twitter["accessTokenSecret"])

	config := &oauth1a.ClientConfig{
		ConsumerKey:    twitter["consumerKey"].(string),
		ConsumerSecret: twitter["consumerSecret"].(string),
	}

	user := oauth1a.NewAuthorizedConfig(twitter["accessToken"].(string), twitter["accessTokenSecret"].(string))
	client = twittergo.NewClient(config, user)

	return client, err
}
開發者ID:blueskywalker,項目名稱:GoLang,代碼行數:33,代碼來源:find.go

示例5: LoadCredentials

func LoadCredentials() (client *twittergo.Client, err error) {
	config := &oauth1a.ClientConfig{
		ConsumerKey:    bot.Config.TwitterConsumerKey,
		ConsumerSecret: bot.Config.TwitterConsumerSecret,
	}
	client = twittergo.NewClient(config, nil)
	return
}
開發者ID:0x263b,項目名稱:Porygon2,代碼行數:8,代碼來源:twitter.go

示例6: LoadCredentials

func LoadCredentials() (client *twittergo.Client, err error) {
	config := &oauth1a.ClientConfig{
		ConsumerKey:    os.Getenv("CONSUMER_KEY"),
		ConsumerSecret: os.Getenv("CONSUMER_SECRET"),
	}
	user := oauth1a.NewAuthorizedConfig(os.Getenv("API_KEY"), os.Getenv("API_SECRET"))
	client = twittergo.NewClient(config, user)
	return
}
開發者ID:postfix,項目名稱:markovmickens,代碼行數:9,代碼來源:markov.go

示例7: createClient

func createClient() *twittergo.Client {
	a := services.Config.Twitter.Auth
	config := &oauth1a.ClientConfig{
		ConsumerKey:    a.Consumer_key,
		ConsumerSecret: a.Consumer_secret,
	}
	user := oauth1a.NewAuthorizedConfig(a.Token, a.Token_secret)
	return twittergo.NewClient(config, user)
}
開發者ID:kienhung,項目名稱:gohome,代碼行數:9,代碼來源:main.go

示例8: loadCredentials

func loadCredentials() (client *twittergo.Client) {
	config := &oauth1a.ClientConfig{
		ConsumerKey:    os.Getenv("twitter_ConsumerKey"),
		ConsumerSecret: os.Getenv("twitter_ConsumerSecret"),
	}
	user := oauth1a.NewAuthorizedConfig(
		os.Getenv("twitter_AccessToken"),
		os.Getenv("twitter_AcessTokenSecret"),
	)
	client = twittergo.NewClient(config, user)
	return
}
開發者ID:chdsbd,項目名稱:wruff.xyz,代碼行數:12,代碼來源:tweet.go

示例9: logIn

// The loading of credentials, the login, and tweeting functionality
// has been addapted from the example provided with github.com/kurrik/twittergo
func logIn(bot *TweetBot) (client *twittergo.Client, err error) {
	if len(bot.credentials) > 0 {
		lines := strings.Split(string(bot.credentials), "\n")
		config := &oauth1a.ClientConfig{
			ConsumerKey:    lines[0],
			ConsumerSecret: lines[1],
		}
		user := oauth1a.NewAuthorizedConfig(lines[2], lines[3])
		client = twittergo.NewClient(config, user)
	}
	return
}
開發者ID:nplatt,項目名稱:tldrtweet,代碼行數:14,代碼來源:tldrtweet.go

示例10: getTwitter

func getTwitter(config Config) *twittergo.Client {
	twitterConfig := &oauth1a.ClientConfig{
		ConsumerKey:    config.Twitter.ConsumerKey,
		ConsumerSecret: config.Twitter.ConsumerSecret,
	}

	user := oauth1a.NewAuthorizedConfig(
		config.Twitter.AccessToken,
		config.Twitter.AccessTokenSecret,
	)

	return twittergo.NewClient(twitterConfig, user)
}
開發者ID:etu,項目名稱:TwitterHAL,代碼行數:13,代碼來源:TwitterHAL.go

示例11: LoadCredentials

func LoadCredentials() (client *twittergo.Client, err error) {
	credentials, err := ioutil.ReadFile("CREDENTIALS")
	if err != nil {
		return
	}
	lines := strings.Split(string(credentials), "\n")
	config := &oauth1a.ClientConfig{
		ConsumerKey:    lines[0],
		ConsumerSecret: lines[1],
	}
	client = twittergo.NewClient(config, nil)
	return
}
開發者ID:carriercomm,項目名稱:twittergo-examples,代碼行數:13,代碼來源:main.go

示例12: NewTwitterUserClient

func NewTwitterUserClient() *twitterComm {
	config := &oauth1a.ClientConfig{
		ConsumerKey:    "my-api-key",
		ConsumerSecret: "my-api-secret",
	}

	user := oauth1a.NewAuthorizedConfig("oauth", "sucks")
	client := twittergo.NewClient(config, user)
	if err := client.FetchAppToken(); err != nil {
		fmt.Println("Error occured creating the client.", err)
		panic("ERROR CREATING USER CLIENT")
	}
	return &twitterComm{client}
}
開發者ID:Melinysh,項目名稱:Project-Clay,代碼行數:14,代碼來源:TwitterComm.go

示例13: LoadCredentials

func LoadCredentials() (client *twittergo.Client, err error) {
	credentials, err := ioutil.ReadFile(credentials)
	if err != nil {
		return
	}
	lines := strings.Split(string(credentials), "\n")
	config := &oauth1a.ClientConfig{
		ConsumerKey:    lines[0],
		ConsumerSecret: lines[1],
	}
	user := oauth1a.NewAuthorizedConfig(lines[2], lines[3])
	client = twittergo.NewClient(config, user)
	return
}
開發者ID:morriswinkler,項目名稱:twitter_proxy,代碼行數:14,代碼來源:twitter.go

示例14: main

func main() {
	// create the config
	config := &oauth1a.ClientConfig{
		ConsumerKey:    twitterConsumerKey,
		ConsumerSecret: twitterConsumerSecret,
	}

	// create the client
	c := twittergo.NewClient(config, nil)
	if err := c.FetchAppToken(); err != nil {
		fmt.Fprintf(os.Stderr, "Could not fetch app token: %v\n", err)
		os.Exit(2)
	}
	// we don't need to save the token I am lazy
	_ = c.GetAppToken()

	// create the request
	v := url.Values{}
	v.Set("q", hashtag)
	req, err := http.NewRequest("GET", "/1.1/search/tweets.json?"+v.Encode(), nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not parse request: %v\n", err)
		os.Exit(2)
	}

	resp, err := c.SendRequest(req)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not send request: %v", err)
		os.Exit(2)
	}

	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())
	}

	sr := &twittergo.SearchResults{}
	if err := resp.Parse(sr); err != nil {
		fmt.Fprintf(os.Stderr, "Problem parsing response: %v\n", err)
		os.Exit(2)
	}
	tweets := sr.Statuses()

	for _, t := range tweets {
		fmt.Println(t.Text())
	}
}
開發者ID:jjperezaguinaga,項目名稱:floppercon,代碼行數:48,代碼來源:main.go

示例15: LoadCredentials

func LoadCredentials() (client *twittergo.Client, err error) {

	twitter, err := readYaml()

	if err != nil {
		return
	}

	config := &oauth1a.ClientConfig{
		ConsumerKey:    twitter["consumerKey"].(string),
		ConsumerSecret: twitter["consumerSecret"].(string),
	}

	user := oauth1a.NewAuthorizedConfig(twitter["accessToken"].(string), twitter["accessTokenSecret"].(string))
	client = twittergo.NewClient(config, user)

	return
}
開發者ID:blueskywalker,項目名稱:GoLang,代碼行數:18,代碼來源:filter.go


注:本文中的github.com/kurrik/twittergo.NewClient函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。