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

Golang twittergo.NewClient函数代码示例

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

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



在下文中一共展示了NewClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: main

func main() {
	config_file, err := ioutil.ReadFile("CREDENTIALS")

	if err != nil {
		return
	}
	lines := strings.Split(string(config_file), "\n")

	config := &oauth1a.ClientConfig{
		ConsumerKey:    lines[0],
		ConsumerSecret: lines[1],
	}

	user := oauth1a.NewAuthorizedConfig(lines[2], lines[3])
	client := twittergo.NewClient(config, user)
	fmt.Println(client)
	fmt.Println(&twittergo.Timeline{})
}
开发者ID:ryopeko,项目名称:sandbox,代码行数:18,代码来源:twitter_sample.go


示例17: loadCredentials

func loadCredentials() *twittergo.Client {
	err := godotenv.Load()
	if err != nil {
		log.Fatal(".env file missing")
	}

	consumerKey := os.Getenv("TWITTER_CONSUMER_KEY")
	consumerSecret := os.Getenv("TWITTER_CONSUMER_SECRET")
	config := &oauth1a.ClientConfig{
		ConsumerKey:    consumerKey,
		ConsumerSecret: consumerSecret,
	}

	accessToken := os.Getenv("TWITTER_ACCESS_TOKEN")
	accessTokenSecret := os.Getenv("TWITTER_ACCESS_TOKEN_SECRET")
	user := oauth1a.NewAuthorizedConfig(accessToken, accessTokenSecret)

	return twittergo.NewClient(config, user)
}
开发者ID:joho,项目名称:goadventure,代码行数:19,代码来源:real_twitter_wrapper.go


示例18: sync

func sync(name string, user *config.User) {
	if user.Enabled {
		weibo_account := user.GetAccount("tsina")
		twitter_account := user.GetAccount("twitter")
		posts := Timeline(weibo_account.Name, user.Last_weibo_id)

		oauth_user := oauth1a.NewAuthorizedConfig(twitter_account.Oauth_token_key, twitter_account.Oauth_token_secret)
		client := twittergo.NewClient(twitter_config, oauth_user)
		for i := len(posts) - 1; i >= 0; i-- {
			post := posts[i]
			if post.Id > user.Last_weibo_id {
				user.Last_weibo_id = post.Id
				tweet, err := Tweet(client, post.Text)
				log.Println(weibo_account.Name, post.Text, tweet)
				if err != nil {
					log.Println("[error]", tweet, err)
				}
			}
		}
	}
}
开发者ID:hugozhu,项目名称:weibo2twitter,代码行数:21,代码来源:twitter.go


示例19: New

// New creates a new instance of the Twitter Social
func New(credentials *social.Credentials) (twitter *Twitter, err error) {

	log.Debugln("Creating a new Twitter Social")
	var user *oauth1a.UserConfig

	if !credentials.AppOnly() {
		log.Debugln("Application only authorization")
		user = oauth1a.NewAuthorizedConfig(credentials.Token, credentials.TokenSecret)
	}

	config := &oauth1a.ClientConfig{
		ConsumerKey:    credentials.Key,
		ConsumerSecret: credentials.Secret,
	}

	client := twittergo.NewClient(config, user)

	// Assign for return value
	twitter = &Twitter{
		api:         client,
		credentials: credentials,
	}
	return
}
开发者ID:Volox,项目名称:GoSocialCrawler,代码行数:25,代码来源:twitter.go


示例20: GetTwitterClient

func GetTwitterClient(ctx appengine.Context) (c *twittergo.Client, err error) {
	var (
		cred   *Credentials
		config *oauth1a.ClientConfig
		user   *oauth1a.UserConfig
	)
	if cred, err = LoadCredentials(ctx); err != nil {
		return
	}
	if cred.ConsumerKey == "" || cred.ConsumerSecret == "" {
		err = fmt.Errorf("Blank consumer secret and/or key")
		return
	}
	config = &oauth1a.ClientConfig{
		ConsumerKey:    cred.ConsumerKey,
		ConsumerSecret: cred.ConsumerSecret,
	}
	if cred.AccessToken != "" {
		user = oauth1a.NewAuthorizedConfig(cred.AccessToken, cred.AccessSecret)
	}
	c = twittergo.NewClient(config, user)
	c.HttpClient = urlfetch.Client(ctx)
	return
}
开发者ID:carriercomm,项目名称:twittergo-examples,代码行数:24,代码来源:app.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang twittergo.APIResponse类代码示例发布时间:2022-05-23
下一篇:
Golang oauth1a.NewAuthorizedConfig函数代码示例发布时间: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