本文整理匯總了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
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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}
}
示例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
}
示例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())
}
}
示例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
}