Exemple #1
0
func NewFlickr(apiKey string, apiSecret string) *Flickr {
	return &Flickr{
		ApiKey:    apiKey,
		ApiSecret: apiSecret,
		Client:    flickr.NewFlickrClient(apiKey, apiSecret),
	}
}
Exemple #2
0
func main() {
	// retrieve Flickr credentials from env vars
	apik := os.Getenv("FLICKRGO_API_KEY")
	apisec := os.Getenv("FLICKRGO_API_SECRET")
	// do not proceed if credentials were not provided
	if apik == "" || apisec == "" {
		fmt.Fprintln(os.Stderr, "Please set FLICKRGO_API_KEY and FLICKRGO_API_SECRET env vars")
		os.Exit(1)
	}

	// create an API client with credentials
	client := flickr.NewFlickrClient(apik, apisec)

	// ask user to authorize this application

	// first, get a request token
	tok, err := flickr.GetRequestToken(client)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}

	// build the authorizatin URL
	url, err := flickr.GetAuthorizeUrl(client, tok)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(3)
	}

	// ask user to hit the authorization url with
	// their browser, authorize this application and coming
	// back with the confirmation token
	var oauthVerifier string
	fmt.Println("Open your browser at this url:", url)
	fmt.Print("Then, insert the code:")
	fmt.Scanln(&oauthVerifier)

	// finally, get the access token
	accessTok, err := flickr.GetAccessToken(client, tok, oauthVerifier)
	fmt.Println("Successfully retrieved OAuth token", accessTok.OAuthToken)

	// check everything works
	resp, err := test.Login(client)
	if err != nil {
		fmt.Println(err)

	} else {
		fmt.Println(resp.Status, resp.User)
	}
}
Exemple #3
0
func main() {
	// retrieve Flickr credentials from env vars
	apik := os.Getenv("FLICKRGO_API_KEY")
	apisec := os.Getenv("FLICKRGO_API_SECRET")
	token := os.Getenv("FLICKRGO_OAUTH_TOKEN")
	tokenSecret := os.Getenv("FLICKRGO_OAUTH_TOKEN_SECRET")
	nsid := os.Getenv("FLICKRGO_USER_ID")

	// do not proceed if credentials were not provided
	if apik == "" || apisec == "" || token == "" || tokenSecret == "" {
		fmt.Fprintln(os.Stderr, "Please set FLICKRGO_API_KEY, FLICKRGO_API_SECRET "+
			"and FLICKRGO_OAUTH_TOKEN, FLICKRGO_OAUTH_TOKEN_SECRET env vars")
		os.Exit(1)
	}

	// create an API client with credentials
	client := flickr.NewFlickrClient(apik, apisec)
	client.OAuthToken = token
	client.OAuthTokenSecret = tokenSecret
	client.Id = nsid

	/*
		response, _ := photosets.GetList(client, false, "23148015@N00", 1)
		fmt.Println(fmt.Sprintf("%+v", *response))

		response, _ := photosets.GetPhotos(client, false, "72157632076344815", "23148015@N00", 1)
		fmt.Println(fmt.Sprintf("%+v", *response))

		response, _ := photosets.EditMeta(client, "72157654143356943", "bar", "Baz")
		fmt.Println(fmt.Sprintf("%+v", *response))

		response, _ := photosets.EditPhotos(client, "72157654143356943", "9518691684", []string{"9518691684", "19681581995"})
		fmt.Println(fmt.Sprintf("%+v", *response))

		response, _ := photosets.RemovePhotos(client, "72157654143356943", []string{"9518691684", "19681581995"})
		fmt.Println(fmt.Sprintf("%+v", *response))

		response, _ := photosets.SetPrimaryPhoto(client, "72157656097802609", "16438207896")
		fmt.Println(fmt.Sprintf("%+v", *response))

		response, _ := photosets.OrderSets(client, []string{"72157656097802609"})
		fmt.Println(fmt.Sprintf("%+v", *response))
	*/

	response, _ := photosets.GetInfo(client, true, "72157656097802609", "")
	fmt.Println(response.Set.Title)
}
Exemple #4
0
func main() {
	// retrieve Flickr credentials from env vars
	apik := os.Getenv("FLICKRGO_API_KEY")
	apisec := os.Getenv("FLICKRGO_API_SECRET")
	token := os.Getenv("FLICKRGO_OAUTH_TOKEN")

	// do not proceed if credentials were not provided
	if apik == "" || apisec == "" || token == "" {
		fmt.Fprintln(os.Stderr, "Please set FLICKRGO_API_KEY, FLICKRGO_API_SECRET "+
			"and FLICKRGO_OAUTH_TOKEN env vars")
		os.Exit(1)
	}

	// create an API client with credentials
	client := flickr.NewFlickrClient(apik, apisec)

	response, _ := oauth.CheckToken(client, token)
	fmt.Println(fmt.Sprintf("%+v", *response))
}
Exemple #5
0
func main() {
	var pause = func() {
		var foo string
		fmt.Println("Press a key to continue")
		fmt.Scanln(&foo)
	}

	// retrieve Flickr credentials from env vars
	apik := os.Getenv("FLICKRGO_API_KEY")
	apisec := os.Getenv("FLICKRGO_API_SECRET")
	token := os.Getenv("FLICKRGO_OAUTH_TOKEN")
	tokenSecret := os.Getenv("FLICKRGO_OAUTH_TOKEN_SECRET")

	// do not proceed if credentials were not provided
	if apik == "" || apisec == "" || token == "" || tokenSecret == "" {
		fmt.Fprintln(os.Stderr, "Please set FLICKRGO_API_KEY, FLICKRGO_API_SECRET "+
			"and FLICKRGO_OAUTH_TOKEN env vars")
		os.Exit(1)
	}

	// create an API client with credentials
	client := flickr.NewFlickrClient(apik, apisec)
	client.OAuthToken = token
	client.OAuthTokenSecret = tokenSecret

	// upload a photo
	path, _ := filepath.Abs("examples/upload/gopher.jpg")
	params := flickr.NewUploadParams()
	params.Title = "A Gopher"
	resp, err := flickr.UploadFile(client, path, params)
	if err != nil {
		fmt.Println("Failed uploading:", err, resp.ErrorMsg())
		os.Exit(1)
	} else {
		fmt.Println("Photo uploaded, id:", resp.Id)
		pause()
	}

	// create a photoset using above photo as primary
	respS, err := photosets.Create(client, "A Set", "", resp.Id)
	if err != nil {
		fmt.Println("Failed creating set:", respS.ErrorMsg())
		os.Exit(1)
	} else {
		fmt.Println("Set created, id:", respS.Set.Id, "url:", respS.Set.Url)
		pause()
	}

	// upload another photo using default params
	path, _ = filepath.Abs("examples/upload/gophers.jpg")
	resp, err = flickr.UploadFile(client, path, nil)
	if err != nil {
		fmt.Println("Failed uploading:", err, resp.ErrorMsg())
		os.Exit(1)
	} else {
		fmt.Println("Photo uploaded, id:", resp.Id)
		pause()
	}

	// assign above photo to the photoset
	respAdd, err := photosets.AddPhoto(client, respS.Set.Id, resp.Id)
	if err != nil {
		fmt.Println("Failed adding photo to the set:", err, respAdd.ErrorMsg())
		os.Exit(1)
	} else {
		fmt.Println("Added photo", resp.Id, "to set", respS.Set.Id)
		pause()
	}

	// remove the photo from the photoset
	respRemP, err := photosets.RemovePhoto(client, respS.Set.Id, resp.Id)
	if err != nil {
		fmt.Println("Failed removing photo from the set:", err, respRemP.ErrorMsg())
		os.Exit(1)
	} else {
		fmt.Println("Removed photo", resp.Id, "from set", respS.Set.Id)
		pause()
	}

	// delete the photoset
	respDelPs, err := photosets.Delete(client, respS.Set.Id)
	if err != nil {
		fmt.Println("Failed removing set:", respDelPs.ErrorMsg())
		os.Exit(1)
	} else {
		fmt.Println("Successfully removed set")
		pause()
	}

	// delete the photo
	respD, err := photos.Delete(client, resp.Id)
	if err != nil {
		fmt.Println("Failed deleting photo:", err)
		fmt.Println(respD.ErrorMsg())
		os.Exit(1)
	} else {
		fmt.Println("Successfully removed photo")
		pause()
	}
}