Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Go API client for 500px

License

NotificationsYou must be signed in to change notification settings

orijtech/500px

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go API client for 500px

CLI

$ go get -u -v github.com/orijtech/500px/cmd/500px

Uploading

  • By path
$ 500px upload --path~/Desktop/hills.jpeg --description"Run view" --title"Hills this evening"
  • From standard input
$ cat~/Downloads/source.png| 500px upload --description"Turn up" --title"issa turn up" --tags vegas,evenings

SDK custom usage

  • Preamble
import ("fmt""log""github.com/orijtech/500px/v1")
  • List photos
funclistPhotos() {client,err:=px500.NewClient()iferr!=nil {log.Fatal(err)}preq:=new(px500.PhotoRequest)preq.LimitPerPage=10preq.MaxPageNumber=2preq.Feature=px500.FeaturePopularpagesChan,cancelFn,err:=client.ListPhotos(preq)iferr!=nil {log.Fatal(err)}count:=uint64(0)forpage:=rangepagesChan {fmt.Printf("Page: #%d\n\n",page.PageNumber)fori,photo:=rangepage.Photos {count+=1fmt.Printf("#%d: %#v\n\n",i,photo)}ifcount>=13 {cancelFn()}fmt.Printf("\n\n")}}*Searchforphotos```gofunc searchForPhotos() {client, err := px500.NewClient()if err != nil {log.Fatal(err)}ps := &px500.PhotoSearch{Term:          "the universe",LimitPerPage:  10,MaxPageNumber: 2,}pagesChan, cancelFn, err := client.SearchPhotos(ps)if err != nil {log.Fatal(err)}count := uint64(0)for page := range pagesChan {fmt.Printf("Page: #%d\n\n", page.PageNumber)if err := page.Err; err != nil {fmt.Printf("err: %v\n", err)continue}for i, photo := range page.Photos {count += 1fmt.Printf("#%d: %#v\n\n", i, photo)}if count >= 13 {cancelFn()}fmt.Printf("\n\n")}}
  • Retrieve a photo by ID
funcfindPhotoByID() {client,err:=px500.NewClient()iferr!=nil {log.Fatal(err)}photo,err:=client.PhotoByID("210717663")iferr!=nil {log.Fatal(err)}fmt.Printf("The Photo's info: %#v\n",photo)}
  • Retrieve comments for a photo
funcretrieveCommentsForPhoto() {client,err:=px500.NewClient()iferr!=nil {log.Fatal(err)}cr:=&px500.CommentsRequest{PhotoID:"210717663",Nested:true,}pagesChan,cancelFn,err:=client.CommentsForPhoto(cr)iferr!=nil {log.Fatal(err)}count:=uint64(0)forpage:=rangepagesChan {fmt.Printf("Page: #%d\n\n",page.PageNumber)iferr:=page.Err;err!=nil {fmt.Printf("err: %v\n",err)continue}fori,comment:=rangepage.Comments {count+=1fmt.Printf("#%d: %#v\n\n",i,comment)forj,reply:=rangecomment.Replies {fmt.Printf("\t\tReply: #%d reply: %#v\n\n",j,reply)}}ifcount>=24 {cancelFn()}fmt.Printf("\n\n")}}
  • Upload a photo
funcuploadAPhoto() {client,err:=px500.NewOAuth1ClientFromEnv()iferr!=nil {log.Fatal(err)}f,err:=os.Open("./v1/testdata/sfPanorama.jpeg")iferr!=nil {log.Fatal(err)}deferf.Close()photo,err:=client.UploadPhoto(&px500.UploadRequest{Body:f,Filename:"billion dollar view",PhotoInfo:&px500.Photo{Title:"SF Panorama, Billion Dollar View",ISO:"iPhone 6",Tags:  []string{"sf","bayBridge","California","Piers"},},})iferr!=nil {log.Fatal(err)}fmt.Printf("Uploaded photo: %#v\n",photo)}
  • Update a photo
funcupdatePhoto() {client,err:=px500.NewOAuth1ClientFromEnv()iferr!=nil {log.Fatal(err)}photo,err:=client.UpdatePhoto(&px500.UpdateRequest{PhotoID:"211020335",Content:&px500.Photo{Title:"Updated in tests",Tags:   []string{"tests","api-client","golang"},Camera:"iphone 6",},})iferr!=nil {log.Fatal(err)}fmt.Printf("Updated photo: %#v\n",photo)}
  • Delete a photo
funcdeletePhoto() {client,err:=px500.NewOAuth1ClientFromEnv()iferr!=nil {log.Fatal(err)}iferr:=client.DeletePhoto("212664703");err!=nil {log.Fatal(err)}fmt.Printf("Successfully deleted the photo!\n")}

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp