Esempio n. 1
0
func main() {
	var consumerKey *string = flag.String("consumerkey", "", "")
	var consumerSecret *string = flag.String("consumersecret", "", "")
	var apiKey *string = flag.String("apikey", "", "")
	flag.Parse()

	c := oauth.NewConsumer(
		*consumerKey,
		*consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "https://www.google.com/accounts/OAuthGetRequestToken",
			AuthorizeTokenUrl: "https://www.google.com/latitude/apps/OAuthAuthorizeToken",
			AccessTokenUrl:    "https://www.google.com/accounts/OAuthGetAccessToken",
		})

	c.AdditionalParams["scope"] = "https://www.googleapis.com/auth/latitude"
	requestToken, url, err := c.GetRequestTokenAndUrl("oob")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("(1) Go to: " + url + "&domain=mrjon.es&granularity=best&location=all")
	fmt.Println("(2) Grant access, you should get back a verification code.")
	fmt.Println("(3) Enter that verification code here: ")

	verificationCode := ""
	fmt.Scanln(&verificationCode)

	accessToken, err := c.AuthorizeToken(requestToken, verificationCode)
	if err != nil {
		log.Fatal(err)
	}

	client, err := c.MakeHttpClient(accessToken)
	if err != nil {
		log.Fatal(err)
	}

	response, err := client.Get(
		fmt.Sprintf("%s?key=%s", CURRENT_LOCATION_URL, *apiKey))
	if err != nil {
		log.Fatal(err)
	}

	defer response.Body.Close()

	bits, err := ioutil.ReadAll(response.Body)
	fmt.Println("Your latest location: " + string(bits))
}
Esempio n. 2
0
func main() {

	tokens = make(map[string]*oauth.RequestToken)

	var (
		consumerKey *string = flag.String(
			"consumerkey",
			"",
			"Consumer Key from Trello. See: https://trello.com/1/appKey/generate",
		)
		consumerSecret *string = flag.String(
			"consumersecret",
			"",
			"Consumer Secret from Trello. See: https://trello.com/1/appKey/generate",
		)
		port *int = flag.Int(
			"port",
			8888,
			"Port to listen on.",
		)
	)

	flag.Parse()

	c = oauth.NewConsumer(
		*consumerKey,
		*consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "https://trello.com/1/OAuthGetRequestToken",
			AuthorizeTokenUrl: "https://trello.com/1/OAuthAuthorizeToken",
			AccessTokenUrl:    "https://trello.com/1/OAuthGetAccessToken",
		},
	)
	// App Name
	c.AdditionalAuthorizationUrlParams["name"] = "Trello OAuth"
	// Token Expiration - Default 30 days
	c.AdditionalAuthorizationUrlParams["expiration"] = "never"
	// Authorization Scope
	c.AdditionalAuthorizationUrlParams["scope"] = "read"
	c.Debug(true)

	http.HandleFunc("/", RedirectUserToTrello)
	http.HandleFunc("/maketoken", GetTrelloToken)
	u := fmt.Sprintf(":%d", *port)
	fmt.Printf("Listening on '%s'\n", u)
	http.ListenAndServe(u, nil)

}
Esempio n. 3
0
func NewTwitter(consumerKey string, consumerSecret string, accessToken string, accessTokenSecret string) *Twitter {
	c := oauth.NewConsumer(
		consumerKey,
		consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "https://api.twitter.com/oauth/request_token",
			AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
			AccessTokenUrl:    "https://api.twitter.com/oauth/access_token",
		})

	return &Twitter{
		consumerKey:    consumerKey,
		consumerSecret: consumerSecret,

		accessToken: oauth.AccessToken{
			Token:  accessToken,
			Secret: accessTokenSecret,
		},

		client: *c,
	}
}
Esempio n. 4
0
func main() {
	tokens = make(map[string]*oauth.RequestToken)

	var consumerKey *string = flag.String(
		"consumerkey",
		"",
		"Consumer Key from Twitter. See: https://dev.twitter.com/apps/new")

	var consumerSecret *string = flag.String(
		"consumersecret",
		"",
		"Consumer Secret from Twitter. See: https://dev.twitter.com/apps/new")

	var port *int = flag.Int(
		"port",
		8888,
		"Port to listen on.")

	flag.Parse()

	c = oauth.NewConsumer(
		*consumerKey,
		*consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "https://api.twitter.com/oauth/request_token",
			AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
			AccessTokenUrl:    "https://api.twitter.com/oauth/access_token",
		},
	)
	c.Debug(true)

	http.HandleFunc("/", RedirectUserToTwitter)
	http.HandleFunc("/maketoken", GetTwitterToken)
	u := fmt.Sprintf(":%d", *port)
	fmt.Printf("Listening on '%s'\n", u)
	http.ListenAndServe(u, nil)
}
Esempio n. 5
0
func main() {
	var consumerKey *string = flag.String(
		"consumerkey",
		"",
		"Consumer Key from Twitter. See: https://dev.twitter.com/apps/new")

	var consumerSecret *string = flag.String(
		"consumersecret",
		"",
		"Consumer Secret from Twitter. See: https://dev.twitter.com/apps/new")

	var postUpdate *bool = flag.Bool(
		"postupdate",
		false,
		"If true, post a status update to the timeline")

	flag.Parse()

	if len(*consumerKey) == 0 || len(*consumerSecret) == 0 {
		fmt.Println("You must set the --consumerkey and --consumersecret flags.")
		fmt.Println("---")
		Usage()
		os.Exit(1)
	}

	c := oauth.NewConsumer(
		*consumerKey,
		*consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "https://api.twitter.com/oauth/request_token",
			AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
			AccessTokenUrl:    "https://api.twitter.com/oauth/access_token",
		})

	c.Debug(true)

	requestToken, u, err := c.GetRequestTokenAndUrl("oob")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("(1) Go to: " + u)
	fmt.Println("(2) Grant access, you should get back a verification code.")
	fmt.Println("(3) Enter that verification code here: ")

	verificationCode := ""
	fmt.Scanln(&verificationCode)

	accessToken, err := c.AuthorizeToken(requestToken, verificationCode)
	if err != nil {
		log.Fatal(err)
	}

	client, err := c.MakeHttpClient(accessToken)
	if err != nil {
		log.Fatal(err)
	}

	response, err := client.Get(
		"https://api.twitter.com/1.1/statuses/home_timeline.json?count=1")
	if err != nil {
		log.Fatal(err)
	}
	defer response.Body.Close()

	bits, err := ioutil.ReadAll(response.Body)
	fmt.Println("The newest item in your home timeline is: " + string(bits))

	if *postUpdate {
		status := fmt.Sprintf("Test post via the API using Go (http://golang.org/) at %s", time.Now().String())

		response, err = client.PostForm(
			"https://api.twitter.com/1.1/statuses/update.json",
			url.Values{"status": []string{status}})

		if err != nil {
			log.Fatal(err)
		}

		log.Printf("%v\n", response)
	}
}
Esempio n. 6
0
func main() {

	var (
		consumerKey *string = flag.String(
			"consumerkey",
			"",
			"Consumer Key from Trello. See: https://trello.com/1/appKey/generate",
		)
		consumerSecret *string = flag.String(
			"consumersecret",
			"",
			"Consumer Secret from Trello. See: https://trello.com/1/appKey/generate",
		)
	)

	flag.Parse()

	if len(*consumerKey) == 0 || len(*consumerSecret) == 0 {

		fmt.Println("You must set the --consumerkey and --consumersecret flags.")
		fmt.Println("---")
		Usage()
		os.Exit(1)
	}

	c := oauth.NewConsumer(
		*consumerKey,
		*consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "https://trello.com/1/OAuthGetRequestToken",
			AuthorizeTokenUrl: "https://trello.com/1/OAuthAuthorizeToken",
			AccessTokenUrl:    "https://trello.com/1/OAuthGetAccessToken",
		},
	)
	// App Name
	c.AdditionalAuthorizationUrlParams["name"] = "Trello OAuth"
	// Token Expiration - Default 30 days
	c.AdditionalAuthorizationUrlParams["expiration"] = "never"
	// Authorization Scope
	c.AdditionalAuthorizationUrlParams["scope"] = "read"

	c.Debug(true)

	requestToken, u, err := c.GetRequestTokenAndUrl("")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("(1) Go to: " + u)
	fmt.Println("(2) Grant access, you should get back a verification code.")
	fmt.Println("(3) Enter that verification code here: ")

	verificationCode := ""
	fmt.Scanln(&verificationCode)

	accessToken, err := c.AuthorizeToken(requestToken, verificationCode)
	if err != nil {
		log.Fatal(err)
	}

	client, err := c.MakeHttpClient(accessToken)
	if err != nil {
		log.Fatal(err)
	}

	response, err := client.Get("https://trello.com/1/members/me")
	if err != nil {
		log.Fatal(err)
	}
	defer response.Body.Close()

	bits, err := ioutil.ReadAll(response.Body)
	fmt.Println("My profiles at Trello are:\n" + string(bits))
}
Esempio n. 7
0
func main() {
	var consumerKey *string = flag.String(
		"consumerkey",
		"",
		"Consumer Key from NetFlix. See: http://developer.netflix.com/apps/mykeys")

	var consumerSecret *string = flag.String(
		"consumersecret",
		"",
		"Consumer Key from NetFlix. See: http://developer.netflix.com/apps/mykeys")

	var appName *string = flag.String(
		"appname",
		"",
		"Application name registered with NetFlix.")

	var debug *bool = flag.Bool(
		"debug",
		false,
		"If true, print debugging information")

	flag.Parse()

	if len(*consumerKey) == 0 || len(*consumerSecret) == 0 || len(*appName) == 0 {
		fmt.Println("You must set the --consumerkey, --consumersecret and --appname flags.")
		os.Exit(1)
	}

	c := oauth.NewConsumer(
		*consumerKey,
		*consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "http://api-public.netflix.com/oauth/request_token",
			AuthorizeTokenUrl: "https://api-user.netflix.com/oauth/login",
			AccessTokenUrl:    "http://api-public.netflix.com/oauth/access_token",
		})

	// See #4 here:
	// http://josephsmarr.com/2008/10/01/using-netflixs-new-api-a-step-by-step-guide/
	c.AdditionalAuthorizationUrlParams = map[string]string{
		"application_name":   *appName,
		"oauth_consumer_key": *consumerKey,
	}

	c.Debug(*debug)

	requestToken, url, err := c.GetRequestTokenAndUrl("oob")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("(1) Go to: " + url)
	fmt.Println("(2) Grant access, you should get back a verification code.")
	fmt.Println("(3) Enter that verification code here: ")

	verificationCode := ""
	fmt.Scanln(&verificationCode)

	accessToken, err := c.AuthorizeToken(requestToken, verificationCode)
	if err != nil {
		log.Fatal(err)
	}

	client, err := c.MakeHttpClient(accessToken)
	if err != nil {
		log.Fatal(err)
	}

	response, err := client.Get(
		"http://api-public.netflix.com/users/current")
	if err != nil {
		log.Fatal(err)
	}
	defer response.Body.Close()

	bits, err := ioutil.ReadAll(response.Body)
	profileXml := Resource{}
	xml.Unmarshal(bits, &profileXml)

	if len(profileXml.Link.Href) == 0 {
		fmt.Println("ERROR: Couldn't parse subscriber-id from: ", string(bits))
		return
	}

	recsUrl := fmt.Sprintf("%s/recommendations?max_results=1&start_index=0",
		profileXml.Link.Href)
	response, err = client.Get(recsUrl)
	if err != nil {
		log.Fatal(err)
	}
	defer response.Body.Close()

	bits, err = ioutil.ReadAll(response.Body)
	fmt.Println("NetFlix recommends: " + string(bits))
}