Ejemplo n.º 1
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
}
Ejemplo n.º 3
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
}