Esempio n. 1
0
func update(filename string, api *go140.API) {
	contents, err := ioutil.ReadFile(filename)
	if err != nil {
		log.Fatal(err)
	}

	_, err = api.Update(string(contents))
	if err != nil {
		log.Println(err)
	}
}
Esempio n. 2
0
func main() {
	flag.Parse()

	if flag.NArg() < 1 {
		fmt.Fprintf(os.Stderr, "Please specify a username!\n")
		os.Exit(-1)
	}

	api := new(go140.API)
	api.Root = "https://api.twitter.com"

	user, err := api.User(flag.Arg(0))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
	}

	line := "Screen name: " + user.ScreenName
	line = padLine(line, 40)
	line += "In real life: " + user.Name
	fmt.Println(line)

	line = "Location: " + user.Location
	line = padLine(line, 40)
	line += "Homepage: " + user.URL
	fmt.Println(line)

	if user.Status == nil {
		os.Exit(0)
	}

	tweetTime, err := time.Parse(time.RubyDate, user.Status.Date)
	if err != nil {
		fmt.Println("Error parsing tweet time: ", err)
		os.Exit(1)
	}
	tweetTime = time.SecondsToLocalTime(tweetTime.Seconds())
	line = "Last tweet " + tweetTime.Format("3:04 PM, Jan _2, 2006")
	fmt.Println(line)
	fmt.Println(user.Status.Text)
}
Esempio n. 3
0
func main() {
	api := new(go140.API)
	authorize(api)

	status, err := api.Status()
	Error(err)
	fmt.Println(status)

	status, err = api.Update("Twitter workflow: edit random test file, change string in API call, recompile, run program. Über sophistication.")

	Error(err)
	fmt.Println(status)

	status, err = api.Status()
	Error(err)
	fmt.Println(status)
}
Esempio n. 4
0
func authorize(api *go140.API) (err os.Error) {
	api.ConsumerKey = "24eNIyd8EskIpi32cYFEbg"
	api.ConsumerSecret = "heXe5AP9tT4jMgWHyF6y17NWJRkJeRX7S7I7W78VmCc"
	api.SignatureMethod = oauth.HMAC_SHA1

	api.RequestTokenURL = "https://api.twitter.com/oauth/request_token"
	api.OwnerAuthURL = "https://api.twitter.com/oauth/authorize"
	api.AccessTokenURL = "https://api.twitter.com/oauth/access_token"
	api.Callback = "oob"

	api.Root = "http://api.twitter.com"

	err = api.Load(home + "/.go140.oauth")
	if err != nil {
		err = api.GetRequestToken()
		Error(err)
		url, err := api.AuthorizationURL()
		Error(err)
		fmt.Printf("Please visit the following URL for authorization:\n%s\n", url)

		var verifier string
		fmt.Printf("PIN: ")
		fmt.Scanf("%s", &verifier)
		err = api.GetAccessToken(verifier)
		Error(err)

		err = api.Save(home + "/.go140.oauth")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Couldn't save authorization information: %s", err)
		}
	}

	return nil
}
Esempio n. 5
0
func authorize(api *go140.API) (err os.Error) {
	api.ConsumerKey = "no6XLKksvxtRHtS3aorzg"
	api.ConsumerSecret = "EJr4Nr9qcT7zjpuLTnmEnMPgNd0I0QEiDh6ksrjLWI"
	api.SignatureMethod = oauth.HMAC_SHA1

	api.RequestTokenURL = "https://api.twitter.com/oauth/request_token"
	api.OwnerAuthURL = "https://api.twitter.com/oauth/authorize"
	api.AccessTokenURL = "https://api.twitter.com/oauth/access_token"
	api.Callback = "oob"

	api.Root = "https://api.twitter.com"

	err = api.Load(authFile)
	if err != nil {
		err = api.GetRequestToken()
		processError(err)
		url, err := api.AuthorizationURL()
		processError(err)
		fmt.Printf("Please visit the following URL for authorization:\n%s\n", url)

		var verifier string
		fmt.Printf("PIN: ")
		fmt.Scanf("%s", &verifier)
		err = api.GetAccessToken(verifier)
		processError(err)

		err = api.Save(authFile)
		if err != nil {
			log.Println("Couldn't save authorization information", err)
		}
	}

	return nil
}