Code Monkey home page Code Monkey logo

flickr's Introduction

flickr

A go library to easily consume Flickr API. The project is currently under heavy development, so it hasn't a version number yet.

GoDoc build-test Coverage Status

Usage

flickr aims to expose a Go Api matching Flickr REST Api, so that you don't need to build HTTP requests and parse HTTP response manually. For example, the Flickr method flickr.photosets.create is implemented with the Create function in the flickr/photosets package:

import "fmt"
import "github.com/OrlovDiga/flickr"
import "github.com/OrlovDiga/flickr/photosets"

// create an API client with credentials
client := flickr.NewFlickrClient("your_apikey", "your_apisecret")
client.OAuthToken = "your_token"
client.OAuthTokenSecret = "your_tokenSecret"

response, _ := photosets.Create(client, "My Set", "Description", "primary_photo_id")
fmt.Println("New photoset created:", response.Photoset.Id)

flickr responses implement flickr.FlickrResponse interface. A response contains error codes and error messages (if any) produced by Flickr or the specific data returned by the api call. Different methods may return different kind of responses.

Upload a photo

There are a number of functions that don't map any actual Flickr Api method (see below for the detailed list). For example, to upload a photo, you call the UploadFile or UploadReader functions in the flickr package:

import "github.com/OrlovDiga/flickr"


// upload the image file with default (nil) options
resp, err := flickr.UploadFile(client, "/path/to/image", nil)

Files are uploaded through an io.Pipe fueled in a separate goroutine, so the process is pretty efficient.

Authentication (or how to retrieve OAuth credentials)

Several api calls must be authenticated and authorized: flickr only supports OAuth since the original token-based method has been deprecated by Flickr. This is an example describing the OAuth worflow from a command line application:

import "github.com/OrlovDiga/flickr"

client := flickr.NewFlickrClient("your_apikey", "your_apisecret")

// first, get a request token
requestTok, _ := flickr.GetRequestToken(client)

// build the authorizatin URL
url, _ := flickr.GetAuthorizeUrl(client, requestTok)

// ask user to hit the authorization url with
// their browser, authorize this application and coming
// back with the confirmation token

// finally, get the access token, setup the client and start making requests
accessTok, err := flickr.GetAccessToken(client, requestTok, "oauth_confirmation_code")
client.OAuthToken = accessTok.OAuthToken
client.OAuthTokenSecret = accessTok.OAuthTokenSecret

Api coverage

Only a small part of the Flickr Api is implemented as Go functions: even if it's quite simple to write the code for the mapping, I only did it for methods I actually need in my projects (contributions well accepted). Anyway, if you need to call a Flickr Api method that wasn't already mapped, you can do it manually:

import "fmt"
import "github.com/OrlovDiga/flickr"

client := flickr.NewFlickrClient("your_apikey", "your_apisecret")
client.Init()
client.Args.Set("method", "flickr.cameras.getBrandModels")
client.Args.Set("brand", "nikon")

client.OAuthSign()
response := &flickr.BasicResponse{}
err := flickr.DoGet(client, response)

if err != nil {
    fmt.Printf("Error: %s", err)
} else {
    fmt.Println("Api response:", response.Extra)
}

Checkout the example folder and the docs pages for more details.

Note on Go versions

The latest version v2 only supports go 1.6 and above, for Go < 1.6 use the v1 package:

go get gopkg.in/masci/flickr.v1

API Methods

Extra-API Methods

These are methods that are not actually part of the Flickr API

  • Get OAuth request token
  • Get OAuth authorize URL
  • Get OAuth access token
  • Upload photo

auth.oauth

  • flickr.auth.oauth.checkToken

photos

  • flickr.photos.delete
  • flickr.photos.getInfo
  • flickr.photos.setDates
  • flickr.photos.setPerms
  • flickr.photos.addTags
  • flickr.photos.getSizes

photosets

  • flickr.photosets.addPhoto
  • flickr.photosets.create
  • flickr.photosets.delete
  • flickr.photosets.editMeta
  • flickr.photosets.editPhotos
  • flickr.photosets.getInfo
  • flickr.photosets.getList
  • flickr.photosets.getPhotos
  • flickr.photosets.orderSets
  • flickr.photosets.removePhoto
  • flickr.photosets.removePhotos
  • flickr.photosets.reorderPhotos
  • flickr.photosets.setPrimaryPhoto

people

  • flickr.people.getPhotos

Groups

  • flickr.groups.pools.add
  • flickr.groups.pools.getGroups
  • flickr.groups.getInfo

test

  • flickr.test.echo
  • flickr.test.login
  • flickr.test.null

flickr's People

Contributors

masci avatar benmesander avatar pankajanand18 avatar focusaurus avatar denisov avatar jpg0 avatar joooostb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.