Git Product home page Git Product logo

flickr-sdk's Introduction

flickr-sdk

Almost certainly the best Flickr API client in the world for node and the browser

This SDK provides methods and type definitions for all methods listed on https://www.flickr.com/services/api/

To use this SDK, sign up for an API key here

install

$ npm install flickr-sdk

quickstart

Make a Flickr API call

import { createFlickr } from "flickr-sdk"

const { flickr } = createFlickr("<your Flickr API key>")

const res = await flickr("flickr.photos.getInfo", {
    photo_id: '12345',
})

Upload a photo

import { createFlickr } from "flickr-sdk"
import { resolve } from "node:path"

const { upload } = createFlickr({
    consumerKey: "<your API key>",
    consumerSecret: "<your API secret>",
    oauthToken: "<the oauth token>",
    oauthTokenSecret: "<the oauth token secret>",
})

const id = await upload(resolve("example.png"), {
    title: "Works on MY machine!",
})

auth

The Flickr SDK currently supports the following auth methods:

API Key

This is the simplest way to use the SDK. Just provide your API key as a string:

const { flickr } = createFlickr("<your API key>")

OAuth 1.0

OAuth lets users grant your application access and then you may act on their behalf. The OAuth flow is described here.

const { upload } = createFlickr({
    consumerKey: "<your API key>",
    consumerSecret: "<your API secret>",
    oauthToken: "<the oauth token>",
    oauthTokenSecret: "<the oauth token secret>",
})

💡 Use examples/oauth.mjs to quickly set up an OAuth flow and obtain a set of credentials

migrating from previous versions

Previous versions of this SDK depended on superagent for http requests. This version of the SDK uses node's native fetch instead, so you now only receive the response body back from an API call. This means the return value of an API call will only be the response body, not a superagent Request

Migrating existing code looks like this:

//  old
const res = await flickr.test.login()
console.log(res.body)

// new
const body = await flickr('flickr.test.login')
console.log(body)

advanced

configuring fetch

import { createFlickr, FetchTransport } from 'flickr-sdk'

const transport = new FetchTransport({
    headers: {
        'user-agent': 'foo',
    }
})

const { flickr } = createFlickr('<your API key>', transport)

testing

import { createFlickr, MockTransport, NullAuth } from 'flickr-sdk'
import * as assert from 'node:assert'

// mock transport returns the response you pass in the constructor
const transport = new MockTransport({
    stat: 'ok',
})

// null auth does nothing
const auth = NullAuth()

const { flickr } = createFlickr(auth, transport)

// makes no network request
const res = await flickr('flickr.photos.getInfo', {
    photo_id: '12345',
})

assert.deepStrictEqual(res, { stat: 'ok', foo: 'bar' })

flickr-sdk's People

Contributors

alex-seville avatar bigbluehat avatar bwg avatar christianhg avatar didoarellano avatar ebisbe avatar jeremyruppel avatar jimwhimpey avatar pdokas avatar seleb avatar smgraywood avatar tomcaserta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flickr-sdk's Issues

Flickr.Upload superagent buffer config

I'm getting a warning "A custom superagent parser has been set but buffering strategy hasn't been configured. Call req.buffer(true of false) or set superagent.buffer[mime] = true or false" when doing file uploads. I think this needs to happen in the Upload constructor.

CORS preflight fails because of custom user-agent header

Doing a request with the SDK from the browser doesn't work any more. The CORS preflight OPTIONS request fails with the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.flickr.com/services/rest?method=flickr.photosets.getPhotos&[...]. (Reason: header ‘user-agent’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response).

The response to the CORS preflight request has the header access-control-allow-origin set to *, which is good, but it also requests that there is an access-control-allow-headers set to user-agent.

This is a bug I noticed only now, but I believe was introduced with #156.
I didn't notice before because I was doing the requests from a server-side rendered home page. So it was only visible when initially loading another page of my website and then going to the home page.

I'm not sure that adding the header access-control-allow-headers to the CORS response is the solution. It is actually not really appropriate that the request is sent from the browser with a custom user-agent header. It should be sent with the browser user-agent value. So ideally, the custom user-agent header should be set only when requests are sent from the server-side.

As, in the end, it will not be mandatory any more to provide a user-agent to call the Flickr API, then maybe the simplest solution is to revert dc79a7a?

Ampersands in API content

Ampersands in descriptions (and possibly elsewhere) appear as &amp;amp; in the Flickr API. It presumably should be &amp;.

Not sure this is the right place to report this, but closest I could find.

Why there are private actions only available for Flickr?

Hello,

I need the total amount of groups a photo belongs to. Right now through the api I have to call photos.getAllContexts and do a count on the pool array. That's overkill when you already have a get totals with the amount that is being used on the website but not on specified on the api.

photos.getAllContexts {
  photo_id: '***',
  per_type_limit: 6,
  get_totals: 1,
  get_all_galleries: 1,
  no_faves_context: 1,
  primary_photo_extras: 'url_sq, url_t, url_s, url_m, needs_interstitial',
  extras: 'can_addmeta,can_comment,can_download,can_print,can_share,contact,content_type,count_comments,count_faves,count_views,date_taken,date_upload,description,icon_urls_deep,isfavorite,ispro,license,media,needs_interstitial,owner_name,owner_datecreate,path_alias,perm_print,realname,rotation,safety_level,secret_k,secret_h,url_sq,url_q,url_t,url_s,url_n,url_w,url_m,url_z,url_c,url_l,url_h,url_k,url_3k,url_4k,url_f,url_5k,url_6k,url_o,visibility,visibility_source,o_dims,publiceditability,system_moderation,datecreate,date_activity,eighteenplus,invitation_only,needs_interstitial,non_members_privacy,pool_pending_count,privacy,member_pending_count,icon_urls,date_activity_detail,muted,owner_name,path_alias,realname,sizes,url_sq,url_q,url_t,url_s,url_n,url_w,url_m,url_z,url_c,url_l,url_h,url_k,url_3k,url_4k,url_5k,url_6k,needs_interstitial'
}

I don't need the extras ( may come in handy in the future ) but I would like to be able to use the get_totals and per_type_limit so I can get a fast response. What do you think @jeremyruppel @alex-seville ??

Groups paginated

Is there a way to get the list of groups that a user belongs but with pagination? I'm trying with a user that has a lot of groups and the queries return a Gateway Timout.

Any idea @superic @jeremyruppel ??

OAuth 1.0 is not supported in the browser

Do you know why im getting this error? please help!
I am using WebPack.

Here is the code:

const Flickr = require('flickr-sdk/flickr-sdk.js');
const {ipcRenderer, remote} = require('electron');
const oauth = new Flickr.OAuth(
    remote.process.env.FLICKR_CONSUMER_KEY,
    remote.process.env.FLICKR_CONSUMER_SECRET
);

screenshot from 2017-10-01 20-50-34

Error when passing Buffer as file argument to Upload

When passing a Buffer of a jpg or png file to Upload, xml2js fails to parse the API response and the following error is thrown:

Non-whitespace before first tag.
Line: 0
Column: 1
Char: o
    SyntaxError: Non-whitespace before first tag.
    Line: 0
    Column: 1
    Char: o
        at /home/user/www/webapp/node_modules/flickr-sdk/plugins/xml.js:39:15
        at Parser.<anonymous> (/home/user/www/webapp/node_modules/xml2js/lib/parser.js:308:18)
        at Parser.emit (events.js:198:13)
        at SAXParser.onerror (/home/user/www/webapp/node_modules/xml2js/lib/parser.js:123:26)
        at emit (/home/user/www/webapp/node_modules/sax/lib/sax.js:624:35)
        at error (/home/user/www/webapp/node_modules/sax/lib/sax.js:653:5)
        at strictFail (/home/user/www/webapp/node_modules/sax/lib/sax.js:677:7)
        at beginWhiteSpace (/home/user/www/webapp/node_modules/sax/lib/sax.js:951:7)
        at SAXParser.write (/home/user/www/webapp/node_modules/sax/lib/sax.js:1006:11)
        at Parser.exports.Parser.Parser.parseString (/home/user/www/webapp/node_modules/xml2js/lib/parser.js:323:31)
        at Parser.parseString (/home/user/www/webapp/node_modules/xml2js/lib/parser.js:5:59)
        at Object.exports.parseString (/home/user/www/webapp/node_modules/xml2js/lib/parser.js:369:19)
        at IncomingMessage.<anonymous> (/home/user/www/webapp/node_modules/flickr-sdk/plugins/xml.js:31:10)
        at IncomingMessage.emit (events.js:203:15)
        at endReadableNT (_stream_readable.js:1145:12)
        at process._tickCallback (internal/process/next_tick.js:63:19)

Call to Upload from my code:

async uploadPhoto (user, buffer) {
  try {
    if (_.isEmpty(user.flickrAuth)) {
      return;
    }

    await new Flickr.Upload(
      this.oauth.plugin(user.flickrAuth.token, user.flickrAuth.secret),
      buffer,
      { is_public: 1 },
    );
  } catch (err) {
    pino.error('Unable to upload user photo');
    throw err;
  }
}

I'm using the multer and sharp libraries to handle uploading and transformation of user photos. The Buffers are successfully uploading to a cloud storage provider, so I can confirm that they're correct. I'm also successfully completing OAuth and retrieving user photos, so the this.oauth object is valid.

consume api on webbrowser

Hello,
Is there a way to consume the api at web browser level with the auhtentication with this SDK?

7.0.0-beta.2: issue finding typescript types

TS is having some issues when trying to location the TS definitions, if I change your package.json file's exports field to this, it works:

  "exports": {
    ".": {
      "import": { "default": "./dist/index.mjs", "types": "./dist/index.d.ts" },
      "require": { "default": "./dist/index.cjs", "types": "./dist/index.d.ts" }
    },
    "./package.json": "./package.json"
  },

Add user-agent

In light of the announcement to require a user-agent for requests made to the Flickr API, it would be good to ensure that a user-agent header is set by the Flickr SDK, for situations when it used server-side, from a Node.js process.

The Flickr SDK uses superagent v6.1.0, which, from the look of this test, doesn't set a user-agent by default (and it's still not the case in the latest version).

Is it planned to make that change? Searching in the code base, I can only find TODOs about user-agent, but nothing else.

Additional params not sent with file upload

When performing a file upload, the additional parameters don't seem to be sent. The file uploads correctly, but no additional information (e.g. title, tags, etc ) gets through. I'm running on Node 6

flickr
  .request( token, secret )
  .media()
  .post(  {
    photo: "path/to/file.jpg",
    title: "My title",
    description: "Custom description",
    tags: "beach sun"
 } )

Please upgrade xml2js to 0.5.0

We are receiving a an error in install the package:

node_modules/xml2js
  flickr-sdk  >=3.1.0
  Depends on vulnerable versions of xml2js
  node_modules/flickr-sdk

Please upgrade the flickr-sdk dependency to 0.5.0

Thanks!!

Get contacts

Hi,

I'm trying to get contacts of the user authenticated, but I have not found any function related how to get them. Is there any way to get them? The user is authenticated using token, and token secret.

Best to all

Hitting 413 (Request Too Large) error on flickr.photosets.editPhotos

I'm attempting to update a photoset with several hundred photos in it, and hitting a 413 response (request too large). Here's what I'm doing:

flickr.photosets.editPhotos({
  photoset_id: albumId,
  photo_ids: photoIds.join(','), // Several hundred IDs in this array
  primary_photo_id: primaryPhotoId
})

I can see from the error response that the bit long set of photo IDs is being passed as a query string param, despite the method being POST:

https://api.flickr.com/services/rest?method=flickr.photosets.editPhotos&photoset_id=72157720077649915&photo_ids=51545392449%2C51545579665%2C51544622751%2C51545369594%2C51545330174...

Is there any way to coerce the library to send the parameters of this method as a post body rather than as a query string? I couldn't see anything obvious in the documentation, but it looks as though the Flickr API itself should support this in principle.

Rest api not working in Browser

After adding .unset('X-Flickr-API-Method') I got the following error:
Error: Parser is unable to parse the response
I've reviwed the code and the error occurs on line 6220 from flickr-sdk.js

Can't pass integer extra params

For example:

flickr.request().media().search(term).get({
      per_page: 10
}).then(response => {
      console.log(response);
});

Will result in: Param per_page with type integer not of the expected type: number

Usage with WebCrypto instead of node's crypto

I'm wanting to make requests to Flickr's api in a Cloudflare Worker, but it provides WebCrypto rather than node's crypto implementation.

This turns out to be causing a real headache especially as the WebCrypto API is asynchronous.

Any pointers gratefully received!

Please add photoset_id to flickr.photos.search

Again this is about the API rather than the javascript client, but it would be great to be able to limit searches to particular albums. The API call just needs a photoset_id parameter.

Caching queries

Would you recomend caching queries? I asume that is not posible with this sdk.

./examples/oauth.js "Secure Connection Failed"

I'm trying ./examples/oauth.js
I get the flickr page, and after I click [OK, I'LL AUTHORIZE IT], I get a "Secure Connection Failed" page

Any hint?

Secure Connection Failed

An error occurred during a connection to localhost:3000. PR_END_OF_FILE_ERROR

    The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
    Please contact the website owners to inform them of this problem.

Suggestion to improve Flickr.Upload

Hi guys,

I think the sdk could be improved as follows:

If we already have:

var flickr = new Flickr(Flickr.OAuth.createPlugin(
  process.env.FLICKR_CONSUMER_KEY,
  process.env.FLICKR_CONSUMER_SECRET,
  process.env.FLICKR_OAUTH_TOKEN,
  process.env.FLICKR_OAUTH_TOKEN_SECRET
));

... then why not just await flickr.upload(file, [args]) rather than having to call a constructor again?

It feels like this would be more intuitive. I've got a module where I create flickr and then I import it wherever I need it. But currently for upload, I have to create the auth function again, call a constructor, and await the resulting promise.

Great library though, I got up and running with the API very quickly.

Cheers,

Ian

Unable to use SDK to get request token

when using the authentication methods on the sdk object I always get invalid_signature returned. I have tried other packages and they work to confirm my api key and secret work. Can you confirm that latest version does authenticate and there is not a bug somewhere in the hashing of the base string.

Missing single quote in ts definition

There is a missing single quote here: https://github.com/flickr/flickr-sdk/blob/main/script/build-types.ejs#L2
Issue added in 6.2

I'm having this issue in my build:

example-app:build: ../node_modules/flickr-sdk/flickr-sdk.d.ts:2:43
example-app:build: Type error: Unterminated string literal.
example-app:build:
example-app:build:   1 | import type { Request } from './lib/request';
example-app:build: > 2 | import type { Response } from 'superagent;
example-app:build:     |                                           ^
example-app:build:   3 | import type OAuth from './services/oauth';
example-app:build:   4 | import type Feeds from './services/feeds';
example-app:build:   5 | import type Upload from './services/upload';

Rollbacking to 6.1.2, latest working version in ts context.

Unable to subscribe to a topic

Hello,

I have tried to subscribe to a topic but I kept getting this response

Callback failed or invalid response: 504

The call I'm doing is:

https://www.flickr.com/services/rest/?method=flickr.push.subscribe&api_key=5e7e5cc502499cc4a4b931ea904a9ae5&topic=my_photos&callback=https%3A%2F%2Fq2gughvxt6.execute-api.eu-west-1.amazonaws.com%2Fpr13%2Fnotifications%2Fphoto-tags%3FuserId%3Denricu5&verify=sync&verify_token=MYTOKEN&format=json&nojsoncallback=1&auth_token=AUTH_TOKEN&api_sig=SIGNATURE

I don't see any calls nor logs from Flickr I only see my tests to check the url. The link in the description is about the PubSub is broken and I have only found little information.

https://pubsubhubbub.github.io/PubSubHubbub/pubsubhubbub-core-0.3.html#subscribing
http://laughingmeme.org/2011/07/24/getting-started-with-flickr-real-time-apis-in-php/

Can you share a sample call from flickr to the subscriber? Is there anything wrong?

Random issues with connection

Hello,
I run into random issues with the api.

Error: connect ECONNREFUSED {ip}:443

Do you know where I can get more information or some contact to solve it?

Thanks

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.