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

Golang oauth1a.NewAuthorizedConfig函数代码示例

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

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



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


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


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


示例18: HandleCreateUserByTwitter

func HandleCreateUserByTwitter(r render.Render, bindErr binding.Errors, userForm models.UserForm, db *models.DB) {
	if bindErr.Count() > 0 {
		r.JSON(400, JsonErrBinding(bindErr))
		return
	}

	// Build Twitter client
	config := &oauth1a.ClientConfig{
		ConsumerKey:    TWITTER_CONSUMER_KEY,
		ConsumerSecret: TWITTER_CONSUMER_SECRET,
	}
	oauthUser := oauth1a.NewAuthorizedConfig(userForm.TwitterAccessToken,
		userForm.TwitterAccessSecret)
	client := twittergo.NewClient(config, oauthUser)

	// Build request to send to Twitter
	req, err := http.NewRequest("GET", "/1.1/account/verify_credentials.json", nil)
	if err != nil {
		log.Println("Could not build request for Twitter:", err.Error())
		r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
	}

	// Send it
	resp, err := client.SendRequest(req)
	if err != nil {
		log.Println("Error sending request to Twitter:", err.Error())
		r.JSON(504, JsonErr("Could not communicate properly with Twitter, "+
			"please try again soon."))
		return
	}

	// Parse the response
	var result = &twittergo.User{}
	if err = resp.Parse(result); err != nil {
		log.Println("Error parsing Twitter result:", err.Error(), "Response:",
			resp)
		r.JSON(504, JsonErr("Got a bad response from Twitter, please try "+
			"again soon."))
		return
	}

	user, err := db.GetUserWithId(result.IdStr())
	if err == nil {
		user, err = db.UpdateUserAuth(user.Id, userForm.TwitterAccessToken,
			userForm.TwitterAccessSecret)
		if err != nil {
			log.Println("Error updating user auth:", err.Error())
			r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
			return
		}
		r.JSON(200, map[string]*models.User{"user": user})
		return
	}

	// Now let's create that user, shall we?
	user, err = db.CreateUser(
		result.IdStr(),
		result.ScreenName(),
		(*result)["profile_image_url"].(string),
		userForm.TwitterAccessToken,
		userForm.TwitterAccessSecret,
	)
	if err != nil {
		log.Println("Error creating user:", err.Error())
		r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
		return
	}

	r.JSON(200, map[string]*models.User{"user": user})
}
开发者ID:AndrewJHart,项目名称:irlmoji,代码行数:70,代码来源:handlers_user.go


示例19: Run

// Run executes the program.
func (m *Main) Run() error {
	logger := log.New(m.Stderr, "", log.LstdFlags)

	// Validate options.
	if m.DataDir == "" {
		return errors.New("data directory required")
	}

	// Create base directory, if not exists.
	if err := os.MkdirAll(m.DataDir, 0777); err != nil {
		return err
	}

	// Open data store.
	m.store = scuttlebutt.NewStore(filepath.Join(m.DataDir, "db"))
	m.store.RemoteStore = github.NewStore(m.Config.GitHub.Token)
	if err := m.store.Open(); err != nil {
		return fmt.Errorf("open store: %s", err)
	}

	// Initialize poller.
	m.poller = twitter.NewPoller()
	m.poller.Client = twittergo.NewClient(&oauth1a.ClientConfig{
		ConsumerKey:    m.Config.Twitter.Key,
		ConsumerSecret: m.Config.Twitter.Secret,
	}, nil)

	// Initialize notifiers for each account
	for _, acc := range m.Config.Accounts {
		client := twittergo.NewClient(
			&oauth1a.ClientConfig{
				ConsumerKey:    m.Config.Twitter.Key,
				ConsumerSecret: m.Config.Twitter.Secret,
			},
			oauth1a.NewAuthorizedConfig(acc.Key, acc.Secret),
		)

		n := twitter.NewNotifier()
		n.Username = acc.Username
		n.Language = acc.Language
		n.Client = client

		m.notifiers = append(m.notifiers, n)
	}

	// Open HTTP listener.
	ln, err := net.Listen("tcp", m.Addr)
	if err != nil {
		return err
	}
	m.Listener = ln
	m.Handler = &scuttlebutt.Handler{Store: m.store}

	// Run HTTP server is separate goroutine.
	logger.Printf("Listening on http://localhost%s", m.Addr)
	go http.Serve(m.Listener, m.Handler)

	// Create a poller & notify monitor.
	m.wg.Add(2)
	go m.runPoller()
	go m.runNotifier()

	return nil
}
开发者ID:boutros,项目名称:scuttlebutt,代码行数:65,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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