Beispiel #1
0
func NewClientWithToken(Consumer *oauth.Consumer, AccessToken string) *http.Client {
	var token oauth.AccessToken
	token.Token = AccessToken
	client, err := Consumer.MakeHttpClient(&token)
	if err != nil {
		log.Error(err)
	}
	return client
}
Beispiel #2
0
func NewClientWithToken(url string, consumer *oauth.Consumer, AccessToken string) *Client {
	var token oauth.AccessToken
	token.Token = AccessToken
	client, err := consumer.MakeHttpClient(&token)
	if err != nil {
		log.Error(err)
	}
	return &Client{client, url, AccessToken}
}
Beispiel #3
0
func saved() *oauth.AccessToken {
	token := oauth.AccessToken{}
	file, err := os.Open(prefix + "/.credentials")
	if err != nil {
		return nil
	}
	defer file.Close()
	bytes, err := ioutil.ReadAll(file)
	if err != nil {
		return nil
	}
	parts := strings.Split(string(bytes), "\n")
	token.Token = parts[0]
	token.Secret = parts[1]
	return &token
}
func getSavedAccessToken() *oauth.AccessToken {
	var token oauth.AccessToken
	file, err := os.Open(TOKEN_FILE)

	if err == nil {
		defer file.Close()
		bytes, err := ioutil.ReadAll(file)

		if err == nil {
			line := string(bytes)

			token_strs := strings.Split(line, "%")
			token.Token = token_strs[0]
			token.Secret = token_strs[1]

			return &token
		}
	}

	return nil
}
Beispiel #5
0
func NewOauth(appKey string, appSecret string, token string, secret string) *http.Client {
	if token == "" || secret == "" || appKey == "" || appSecret == "" {
		util.Error("token can't be empty\n")
		return nil
	}
	consumer := oauth.NewConsumer(
		appKey,
		appSecret,
		oauth.ServiceProvider{
			"", "", "", "",
		})

	t := new(oauth.AccessToken)
	t.Token = token
	t.Secret = secret

	client, err := consumer.MakeHttpClient(t)

	if err != nil {
		util.Error("%s\n", err.Error())
		return nil
	}
	return client
}