• Stars
    star
    644
  • Rank 69,400 (Top 2 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript client for the Tumblr API

tumblr.js

CI npm

The official JavaScript client library for the Tumblr API. Check out the detailed documentation here.

Installation

Install this package from npm:

npm install --save tumblr.js

Usage

Authentication

Different API methods use different kinds of authentication.

Most of them require at least an API key, which will require you to register an application. The OAuth Consumer Key is your API key.

For methods that require a fully signed request, you'll need OAuth tokens as well, which you get from authenticating as a Tumblr user and allowing access to your API application. Here's the easy way to do it with our own account:

  1. Visit the OAuth applications page
  2. Click "Explore API" on the application you want to authorize
  3. Click the "Allow" button, which will take you to the API console
  4. Click the "Show keys" button, which will show you the credentials you can use to make signed requests.

If you're building an application of your own for users out in the world, you'll need to go through the 3-legged OAuth flow. See the help docs for more info.

In Node.js

const tumblr = require('tumblr.js');
const client = tumblr.createClient({
  consumer_key: '<consumer key>',
  consumer_secret: '<consumer secret>',
  token: '<oauth token>',
  token_secret: '<oauth token secret>',
});

Or, if you prefer:

const tumblr = require('tumblr.js');
const client = new tumblr.Client({
  // ...
});

The request methods will return promises. The callback form is considered deprecated and should not be used.

In the Browser

Due to CORS restrictions, you're going to have a really hard time using this library in the browser. Although GET endpoints on the Tumblr API support JSONP, this library is not intended for in-browser use. Sorry!

Example

// Show user's blog names
client.userInfo(function (err, data) {
  data.user.blogs.forEach(function (blog) {
    console.log(blog.name);
  });
});

Supported Methods

Below is a list of available methods and their purpose. Available options are documented in the API Docs and are specified as a JavaScript object.

const response = await client.blogPosts('blogName', {
  type: 'photo',
  tag: ['multiple', 'tags', 'likethis'],
});

In most cases, since options are optional (heh) they are also an optional argument, so there is no need to pass an empty object when supplying no options, like:

const response = await client.blogPosts('blogName');

User Methods

// Get information about the authenticating user & their blogs
const userInfo = await client.userInfo();

// Get dashboard for authenticating user
const userDashboard = await client.userDashboard(options);

// Get likes for authenticating user
const userLikes = await client.userLikes(options);

// Get followings for authenticating user
const userFollowing = await client.userFollowing(options);

// Follow or unfollow a given blog
await client.followBlog(blogURL);
await client.unfollowBlog(blogURL);

// Like or unlike a given post
await client.likePost(postId, reblogKey);
await client.unlikePost(postId, reblogKey);

Blog Methods

// Get information about a given blog
const blogInfo = await client.blogInfo(blogName);

// Get a list of posts for a blog (with optional filtering)
const blogPosts = await client.blogPosts(blogName, options);

// Get the avatar URL for a blog
const blogAvatar = await client.blogAvatar(blogName);

// Get the likes for a blog
const blogLikes = await client.blogLikes(blogName, options);

// Get the followers for a blog
const blogFollowers = await client.blogFollowers(blogName, options);

// Get the queue for a blog
const blogQueue = await client.blogQueue(blogName, options);

// Get the drafts for a blog
const blogDrafts = await client.blogDrafts(blogName, options);

// Get the submissions for a blog
const blogSubmissions = await client.blogSubmissions(blogName, options);

Post Methods

Create a post with createPost

await client.createPost(blogName, options);

To upload media with a created post, provide a ReadStream as the block media:

await client.createPost(blogName, {
  content: [
    {
      type: 'image',
      // Node's fs module, e.g. `import fs from 'node:fs';`
      media: fs.createReadStream(new URL('./image.jpg', import.meta.url)),
      alt_text: '…',
    },
  ],
});

Create a post with editPost

await client.editPost(blogName, postId, options);

Create a post with deletePost

await client.deletePost(blogName, postId);

Legacy Post Methods (deprecated)

// Create a legacy post
const createdPost = await client.createLegacyPost(blogName, options);

// Edit a legacy post
await client.editLegacyPost(blogName, options);

// Reblog a legacy post
await client.reblogPost(blogName, options);

Tagged Methods

// View posts tagged with a certain tag
client.taggedPosts(tag, options);
client.taggedPosts(tag);

Unsupported Methods

You can make arbitrary requests via the following methods.

// GET requests
client.getRequest(apiPath, params);

// POST requests
client.postRequest(apiPath, params);

// PUT requests
client.postRequest(apiPath, params);

Running Tests

# Run tests
npm run test

# Lint
npm run lint

# Typecheck
npm run typecheck

See CONTRIBUTING.md for more details including the integration tests.


Copyright and license

Copyright 2013-2019 Tumblr, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations.

More Repositories

1

Backboard

A motion-driven animation framework for Android.
Java
1,694
star
2

Graywater

An Android library for decomposing RecyclerView layouts to improve scroll performance.
Java
1,209
star
3

colossus

I/O and Microservice library for Scala
Scala
1,144
star
4

jetpants

MySQL toolkit for managing billions of rows and hundreds of database machines
Ruby
1,136
star
5

pytumblr

A Python Tumblr API v2 Client
Python
723
star
6

collins

groovy kind of love
Scala
572
star
7

Bookends

A UI widget for adding headers and footers to RecyclerView
Java
539
star
8

Remember

A preferences-backed key-value store
Java
523
star
9

policy

Tumblr policies and guidelines
453
star
10

laphs

Apple Live Photo support on the web, courtesy of Tumblr
JavaScript
447
star
11

TMTumblrSDK

Unopinionated and flexible library for easily integrating Tumblr data into your iOS or OS X application.
Objective-C
432
star
12

tumblr.php

Tumblr API v2 PHP Client
PHP
407
star
13

k8s-sidecar-injector

Kubernetes sidecar injection service
Go
343
star
14

kanvas-ios

Kanvas: a creation tool for iOS
Swift
312
star
15

jumblr

Tumblr API v2 Java Client
Java
277
star
16

gocircuit

Go
237
star
17

genesis

A tool for data center automation
Ruby
156
star
18

docker-registry-pruner

Tool to apply retention logic to docker images in a Docker Registry
Go
127
star
19

data-lasso

JavaScript
119
star
20

docs

Tumblr's public platform documentation.
107
star
21

XExtensionItem

Easier sharing of structured data between iOS applications and share extensions
Objective-C
88
star
22

PermissMe

Java
75
star
23

webpack-web-app-manifest-plugin

A webpack plugin that generates a PWA manifest and integrates with the assets JSON.
JavaScript
75
star
24

k8s-secret-projector

Kubernetes Secret generation from secure credential repos
Go
72
star
25

k8s-config-projector

Create Kubernetes ConfigMaps from configuration files
Go
65
star
26

tumblrclient.go

This is a concrete implementation of the ClientInterface with additional convenience methods defined right on the client object
Go
42
star
27

go-collins

Collins API Client in Go - https://tumblr.github.io/collins
Go
41
star
28

tumblr.go

This is a library which provides structs and functions for accessing the Tumblr API
Go
37
star
29

JXHTTP

you know, for networking
Objective-C
25
star
30

Spectacles

A tiny library for parsing JSON podspecs.
Objective-C
23
star
31

gulp-css-hashes

JavaScript
18
star
32

tsd_proxy

Clojure
15
star
33

tumblr-repl

REPL for the Tumblr API, built on tumblr.js
JavaScript
12
star
34

collins_shell

Ruby
3
star
35

consolr

Ruby
1
star
36

chorus-timekeeper

DI with timekeeping.
PHP
1
star
37

collins_client

Ruby
1
star
38

collins_notify

Ruby
1
star
39

collins_auth

Ruby
1
star
40

slackr_archiver

Ruby
1
star