本文整理汇总了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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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}
}
示例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
}
示例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}
}
示例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
}
示例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,
}
}
示例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{})
}
示例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)
}
示例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)
}
}
}
}
}