当前位置: 首页>>代码示例>>Golang>>正文


Golang oauth1a.NewAuthorizedConfig函数代码示例

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


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

示例1: twitterImage

func twitterImage(sess models.OAuthAuthorizedToken) string {
	query := url.Values{}
	query.Set("screen_name", sess.ScreenName)
	url := fmt.Sprintf("https://api.twitter.com/1.1/users/show.json?%v", query.Encode())

	req, e1 := http.NewRequest("GET", url, nil)
	if e1 != nil {
		logs.Error.Printf("Could not get new request: %v", e1)
		return ""
	}
	twitter.Sign(req, oauth1a.NewAuthorizedConfig(sess.AccessTokenKey, sess.AccessTokenSecret))

	client := &http.Client{}
	res, e2 := client.Do(req)
	if e2 != nil {
		logs.Error.Printf("Could not send HTTP request: %v", e2)
		return ""
	}
	defer res.Body.Close()

	body, e3 := ioutil.ReadAll(res.Body)
	if e3 != nil {
		logs.Error.Printf("Could not read HTTP response: %v", e3)
		return ""
	}
	type user struct {
		ProfileImageURL string `json:"profile_image_url"`
	}
	var u user
	if err := json.Unmarshal(body, &u); err != nil {
		logs.Error.Printf("Error: %v", err)
		return ""
	}
	return u.ProfileImageURL
}
开发者ID:pottava,项目名称:golang-microservices,代码行数:35,代码来源:twitter.go

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

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

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

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

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

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

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

示例9: 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:lafisrap,项目名称:21tweet,代码行数:14,代码来源:tweeter.go

示例10: NewTumblrRequest

//Initializes the TumblrRequest.
//consumerKey is the consumer key of your Tumblr Application.
//consumerSecret is the consumer secret of your Tumblr Application.
//callbackUrl is the callback URL of your Tumblr Application.
//oauthToken is the user specific token, received from the /access_token endpoint.
//oauthSecret is the user specific secret, received from the /access_token endpoint.
//host is the host that you are tryng to send information to (e.g. http://api.tumblr.com).
func NewTumblrRequest(consumerKey, consumerSecret, oauthToken, oauthSecret, callbackUrl, host string) *TumblrRequest {
	service := &oauth1a.Service{
		RequestURL:   "http://www.tumblr.com/oauth/request_token",
		AuthorizeURL: "http://www.tumblr.com/oauth/authorize",
		AccessURL:    "http://www.tumblr.com/oauth/access_token",
		ClientConfig: &oauth1a.ClientConfig{
			ConsumerKey:    consumerKey,
			ConsumerSecret: consumerSecret,
			CallbackURL:    callbackUrl,
		},
		Signer: new(oauth1a.HmacSha1Signer),
	}
	userConfig := oauth1a.NewAuthorizedConfig(oauthToken, oauthSecret)
	return &TumblrRequest{service, userConfig, host, consumerKey}
}
开发者ID:kanosaki,项目名称:gotumblr,代码行数:22,代码来源:request.go

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

示例12: New

// This is the initialization method.
// An easy way to get the credentials is to access the interactive console:
// https://api.tumblr.com/console
func New(consumerKey, consumerSecret, oauthKey, oauthSecret string) *Tumblr {
	service := &oauth1a.Service{
		RequestURL:   requestTokenUrl,
		AuthorizeURL: authorizeUrl,
		AccessURL:    accessTokenUrl,
		ClientConfig: &oauth1a.ClientConfig{
			ConsumerKey:    consumerKey,
			ConsumerSecret: consumerSecret,
		},
		Signer: new(oauth1a.HmacSha1Signer),
	}
	config := oauth1a.NewAuthorizedConfig(oauthKey, oauthSecret)
	return &Tumblr{
		oauthService: *service,
		config:       *config,
		apiKey:       consumerKey,
	}
}
开发者ID:mattcunningham,项目名称:gumblr,代码行数:21,代码来源:tumblr.go

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

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

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


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