Coder Social home page Coder Social logo

tumblr.js's Introduction

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: '…',
    },
  ],
});

Edit a post with editPost

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

Delete 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.putRequest(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.

tumblr.js's People

Contributors

adamgauthier avatar bjornstar avatar ceyko avatar codingjester avatar cubeghost avatar cyle avatar daltomania avatar defect avatar dependabot[bot] avatar gravityrail avatar irace avatar jasonpenny avatar jhorbulyk avatar jlobos avatar john-raymon avatar kmck avatar komapa avatar ngreenwood6 avatar notjosh avatar oleglitvin avatar pimuzzo avatar roderickhsiao avatar rosano avatar sanmai avatar scriptype avatar seejohnrun avatar shahkashani avatar sirreal avatar sndsgd avatar straku 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  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

tumblr.js's Issues

Get Access Token

I can get the access token of tumblr through the javascript library?

Missing client.posts() function

I'm using the tumblr API console (https://api.tumblr.com/console/calls/blog/posts) to set up my request. I desire to use client.posts() to receive an image url, however, client.posts() returns a missing function error when I run the command on my machine.

client.blogPosts() works, however, this function does not return the same JSON response that I need to access image urls like client.posts() does in the api console.

Multiple image posting support

Posting photosets isn't currently supported. Adding this issue in for reference if someone is ever looking for information on this in the issue history.

I've made a pull for it here: #23.

Consider loosen request dependency?

Currently we are hard coded request version in the dependency, which potentially increase the user package size by downloading multiple version of those downstream dependencies.

Are we consider loosen the dependency version to something like ^2.0.0? (lock down major)

edit() returns 400 error for asks

I have a script to bulk privatize my old posts. It works for all post types except asks, which give me a 400 error response.

Editing an ask from bin/repl.js:

> tumblr.edit('kxsong.tumblr.com',{id: 91578549960, state:"private"}, function(err,rsp){console.log(err);console.log(rsp)});
undefined
> [Error: API error: 400 Bad Request]
undefined

Editing a regular post:

> tumblr.edit('kxsong.tumblr.com',{id: 91579028580, state:"private"}, function(err,rsp){console.log(err);console.log(rsp)});
undefined
> null
{ id: 91579028580 }

Feature: add one function 'notes' under `Blog methods`...

Suppose the following scene: i love nba star cp3,somebody post the infomation or video about Paul, i want to know more about Paul or the people that also likes paul. How can i get these info?
Here is my opinion: I can find that by find who also love the post about Paul, so, the function notes is follow:

/**
   * get one post's notes,includes like or reblog
   * @param  {string}   blogName     bolg name
   * @param  {int}        id                  post id
   * @param  {Function} callback 
   */
notes:function(blogName, id, callback){
    this._get(blogPath(blogName,'/notes'),{id:id},callback,true);
  },

and see this

client.notes('lovingbasketball',92886654550,function(err,data){
    var noters = new Array();
    noters['like'] = new Array();
    noters['reblog'] = new Array();
    data.notes.forEach(function(blog){
        noters[blog.type].push(blog.blog_name);
    });
    console.log(noters);
    //return noters;
});

by this way, i get the follow message:

[ 
    like: ['jraw81','likahbaby','kidhattan','jstarkk','fernvndoec',...],
    reblog: [ 'f32guson','giotabliashvili','jsandjays','asweproceedto',...] 
]

Posting photo with empty caption causes 401 error

Not sure exactly what the cause is, but passing empty parameters (e.g. caption) into the TumblrClient.photo function causes the Tumblr API to return a 401 Not Authorized error. I think it might have something to do with signing the request.

Since captions were user-generated on our platform, this caused a puzzling intermittent 401 error. Please fix this or at least update the documentation to warn people not to include empty parameters.

Replace node's query-string with URLSearchParams

Why?
The WHATWG Standard uses a more selective and fine grained approach to selecting encoded characters than that used by the Legacy API. It's avalible in node, deno and browser, so it will be more light weight when compiling tumblr to eg browser

- const qs = require('query-string');

...

    return requestGet(extend({
-        url: baseUrl + apiPath + '?' + qs.stringify(params),
+        url: baseUrl + apiPath + '?' + new URLSearchParams(params),
        oauth: credentials,
        json: true,
    }, requestOptions), requestCallback(callback));   
  "dependencies": {
    "lodash": "^4.17.11",
-    "query-string": "^6.1.0",
    "request": "^2.88.0"
  },

Errors in Nested Dependencies

Not sure if I should bother reporting this here, as it seems to be a hard-requirement in the nested dependencies. However, I noticed that when I try to make posts in node 0.12.4 on Ubuntu 14.04 using tumblr.js I receive the following:

me@here:~/code/tumblr-lorem$ node tumblrLorem.js
configuring application
including dependencies
preparing oauth
connected
submitting photo post: {
"type": "photo",
"tags": [
"cross-platform",
"online",
"multi-byte",
"primary"
],
"caption": "iusto asperiores ullam consequuntur amet repudiandae natus voluptatem",
"link": "https://brody.com",
"source": "http://lorempixel.com/136/372"
}
/home/me/code/tumblr-lorem/node_modules/tumblr.js/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js:41
stream.on('data', this._checkDataSize.bind(this));
^
TypeError: undefined is not a function
at FormData.CombinedStream.append (/home/me/code/tumblr-lorem/node_modules/tumblr.js/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js:41:14)

this "combined_stream" thing is a nested dependency of form-data, and form-data is using a hard-coded version of 0.0.3 -- combined_stream is upto 1.0.5: https://www.npmjs.com/package/combined-stream

This might be due to a hardcoded parent dependency? Dunno. But it's causing my posting to not go through. I can manually update the package files myself, but that isn't very good.

My code is here:
https://github.com/shadesoflight/tumblr-lorem/blob/develop/tumblrLorem.js#L39

access token

how to get access token and token secret by login flow.

client.userFollowing is returning empty blogs despite blogs being followed

Here is my script:

// Authenticate via OAuth
var tumblr = require('tumblr.js');
var client = tumblr.createClient({
	consumer_key: 'a',
	consumer_secret: 'b',
	token: 'c',
	token_secret: 'd'
});

// Unfollow everyone
function unfollowall () {
	return new Promise(function (resolve, reject) {
		client.userFollowing(function (err, data) {
			if (err) {
				reject(err)
			}
			else if (data.total_blogs === 0) {
				resolve()
			} else if (data.blogs.length === 0) {
				console.error(data)
				reject(new Error('no blogs returned'))
			} else if (data.blogs.length) {
				console.log('unfollowing:', data.blogs.length, 'blogs')
				return Promise.all(
					data.blogs.map((blog) => new Promise(function (resolve, reject) {
						client.unfollowBlog(blog.url, function (err, data) {
							if (err) reject(err)
							console.log('unfollowed:', blog.url)
							resolve()
						})
					}))
				).then(unfollowall)
			}
			else {
				console.error(data)
				reject(new Error('invalid response'))
			}
		})
	})
}

// App
unfollowall().then(console.log.bind('all good'))
	.catch(function (err) {
		if (err.toString().includes('Limit Exceeded')) {
			console.log('reached rate limits, waiting a minute')
			setTimeout(unfollowall, 60 * 1000)
		}
		else {
			return Promise.reject(err)
		}
	})
	.catch(console.error.bind('all bad'))

When I run it with the credentials filled in, I get:

> node index.js 
{ total_blogs: 1283, blogs: [] }
Error: no blogs returned
    at /Users/balupton/Projects/active/tumblr-unfollowall/index.js:21:12
    at Request._callback (/Users/balupton/Projects/active/tumblr-unfollowall/node_modules/tumblr.js/lib/tumblr.js:452:20)
    at Request.self.callback (/Users/balupton/Projects/active/tumblr-unfollowall/node_modules/request/request.js:185:22)
    at Request.emit (events.js:182:13)
    at Request.<anonymous> (/Users/balupton/Projects/active/tumblr-unfollowall/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:182:13)
    at IncomingMessage.<anonymous> (/Users/balupton/Projects/active/tumblr-unfollowall/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:273:13)
    at IncomingMessage.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)

Why is the blogs array empty, despite 1283 blogs being followed?

[Error: API error: 401 Unauthorized]

Hi,

I get authentication error in reblog of post, the code is based from https://api.tumblr.com/console/calls/post/reblog i failed to resolve 😫

var tumblr = require('tumblr.js');

var client = tumblr.createClient({
  consumer_key: '',
  consumer_secret: '',
  token: '',
  token_secret: ''
});

client.reblog('biorandom.tumblr.com', {
  id: 132680518497,
  reblog_key: '5UmjEEzJ'
}, function (err, data) {
  console.log(err, data);
});

out

[Error: API error: 401 Unauthorized] undefined

native_inline_images option borks

Using native_inline_images option for photo posts is failing.

client.photo(req.body.blogname, {
        source: 'https://img.buzzfeed.com/buzzfeed-static/static/2014-04/enhanced/webdr03/4/16/enhanced-26552-1396642701-1.jpg?no-auto',
        native_inline_images: true,
    }, function(){});

Stack trace:

_http_outgoing.js:443
    throw new TypeError('first argument must be a string or Buffer');
    ^

TypeError: first argument must be a string or Buffer
    at ClientRequest.OutgoingMessage.write (_http_outgoing.js:443:11)
    at Request.write (/Volumes/space/server/node_modules/request/request.js:1371:25)
    at FormData.ondata (stream.js:31:26)
    at emitOne (events.js:90:13)
    at FormData.emit (events.js:182:7)
    at FormData.CombinedStream.write (/Volumes/space/server/node_modules/combined-stream/lib/combined_stream.js:118:8)
    at FormData.CombinedStream._pipeNext (/Volumes/space/server/node_modules/combined-stream/lib/combined_stream.js:106:8)
    at FormData.CombinedStream._getNext (/Volumes/space/workspace/server/node_modules/combined-stream/lib/combined_stream.js:79:10)
    at FormData.CombinedStream._pipeNext (/Volumes/space/workspace/server/node_modules/combined-stream/lib/combined_stream.js:107:8)
    at FormData.CombinedStream._getNext (/Volumes/space/server/node_modules/combined-stream/lib/combined_stream.js:79:10)

Need some examples

README is full of options arguments and not a single example of how to use it. How would I retrieve /posts with photos only?

EDIT: I had to look at the source code to find out how to do it. If anyone else has run into the same issue it is:

client.posts('peacecorps.tumblr.com', { type: 'photo' }, function(err, data) {

});

Tumblr.js Link posts API not the same as website

I'd like to be able to post link posts on a blog exactly the same way as if you were to go on the regular user interface and choose a "link" post and paste in a URL. It automatically grabs the image, sizes it, sets the title and a body/caption.

How do I go about doing this with the tumblr.js api wrapper?

Post created return post id?

Hi, sorry about my english.

  • Call client.video(blogName, options, callback); => callback success return "id";
  • I try : myblog.tumblr.com/post/"id" => return Not Found.
    "id" is not postId?
    thanks.

Reblog and 401 error

Hi, im trying to reblog some post but i got the 401 error all the time...

my code :

var Tok;
var Stok;
var tumblr = require('tumblr.js');
var OAuth = require('oauth').OAuth;
  var oa = new OAuth(
      'http://www.tumblr.com/oauth/request_token',
      'http://www.tumblr.com/oauth/access_token',
      'MY - consumer_key',
      'MY - consumer_secret',
 "1.0A", null, "HMAC-SHA1");

  oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results) {
    if (error) return 401;
    console.log(oauth_token,oauth_token_secret,results);
    accessToken=oauth_token;
    accessTokenSecret=oauth_token_secret;
    var Tok = oauth_token;
    var Stok= oauth_token_secret;

      if (Tok != undefined) {
        var client = tumblr.createClient({
          consumer_key: 'MY - consumer_key',
          consumer_secret: 'MY - consumer_secret',
          token: "'"+Tok+"'",
          token_secret: "'"+Stok+"'"
        });
      }
        console.log(Stok);

  function init(){
    console.log("-------- INIT --------");
      if (Stok != undefined) {
        client.reblogPost('my-blog.tumblr.com', { id: postId, reblog_key: key }, function (err, data) {
            if (err) {
              console.log(err);
            } else {
            console.log('Reblog -= [OK] =-');
            }
        });
      }
  }
setTimeout(init,5000);
});

Im very bad with Callback etc... Can you help me to fix my code please ^^. (Im a newbies with nodejs but i can work with that) Please be Kind ^^.

current version, NPM publish

Hey for me it looks like, the current github version is not published on npm, therefore we
can't use multipicture uploads (see #63).

Thanks in advance
Oliver

Update unsecure dependency

One of tumblr.js's dependencies, request, contains a child dependency with a security vulnerability (hoek). As of 5 days ago, a new version of request was published without this vulnerability (see comment here).

Could you please bump the required version of request to ^2.87.0?

Thanks!

Basic example error 'require is not defined'

My code (from api.tumblr.com/console):

<script>
    var tumblr = require('./js/tumblr.js');
    var client = tumblr.createClient({ consumer_key: '<key>' });
    // Make the request
    client.posts('my-blog.tumblr.com', { type: 'text', notes_info: true, filter: 'html' }, function (err, data) {
        // ...
    });
</script>

Get error message:

Uncaught ReferenceError: require is not defined.

Help me pls.

Support data64 images

The requireOptions for photo postCreation doesn't account for the data64 option. Passing the image as data64 produces this error.

Error: Missing one of: data,source
    at requireValidation (/Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/tumblr.js/lib/tumblr.js:231:13)
    at Object.photo (/Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/tumblr.js/lib/tumblr.js:31:7)
    at /Volumes/space/workspace/otherside-me_aura/aura-server/routes/tumblr.js:70:9
    at Layer.handle [as handle_request] (/Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/express/lib/router/layer.js:95:5)
    at next (/Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/express/lib/router/layer.js:95:5)
    at /Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/express/lib/router/index.js:330:12)
    at next (/Volumes/space/workspace/otherside-me_aura/aura-server/node_modules/express/lib/router/index.js:271:10)

Adding base64 here doesn't fix it, either.

[Error: API error: 400 Bad Request]

Here is my code. Using a source url posts the photo with no issues.

client.photo(req.body.blogname, {
        data64: req.body.image,
        // source: 'https://img.buzzfeed.com/buzzfeed-static/static/2014-04/enhanced/webdr03/4/16/enhanced-26552-1396642701-1.jpg?no-auto'
    }, function(){});

How to post to queue

I'm using client.txt from the post methods. How can I post to queue instead of the published default?

Documentation very unclear on photo data format

The documentation points you at the Tumblr API docs eg https://www.tumblr.com/docs/en/api/v2#posting for options information, however for photo posting this is pretty inaccurate. For photo posts the API docs say:

Array (URL-encoded binary contents)

as the format for photo data. Base-64, URL-encoded seems to be what you want. A user of this JS API could easily (and at least one has :P) spend a lot of time trying to work out why their lovingly crafted image data isn't uploading, when in fact all they needed to give was the local filename and have it handled for them.

Posting inline photos

On Tumblr's UI, it's possible to add inline photos to a post if you are in rich-text mode. It would be useful to be able to upload photos for inline use through the API.

When you upload through the UI, the photo is uploaded to Tumblr and the URL is then added to the source code of the post. You can see this by switching from rich-text to HTML or Markdown modes.

The photo is uploaded to a location similar to photo-type posts' photos but the filename seems to be obfuscated and prepended with tumblr_inline_.

I can't see a way to do this through the API at the moment, except by adding them as draft photo posts which is far ideal, but there may be a way I'm not aware that could be added as a feature/function of this package.

BlogInfo response = null

So when I try to pull the blog info for any blog, I just get "null", though I know it's letting me access the API because when I log the response for client.blogPosts, I actually get all the blogs posts.

My code:

client.blogInfo(name, function(err, resp) {
    console.log(resp)
})

Access Tokens

Hi,

could you tell me how can I get the access tokens?
token: '',
token_secret: ''

Are they part of the OAuth request response?
We've created the app with a tumblr user but the app is not accepted by the blog, how we can fix that?
Thanks a lot.

Repeating posts in Dashboard API

Hi, that's my code:

client.userDashboard({
    type: 'photo',
    limit: 20,
    offset: offset
}).then(function (result){
    response.send(result);
}).catch(function (err){
    console.log('ERROR', err);
});

I'm using a infinite scrolling way and after some pages the result starts looping and is equal.

I increment the offset like this:

offset = _offset + limit + 1;

P.S. Sorry my english (=

Response body is object for GET and string for POST

For any GET request, if you inspect response.body it is an object. But if you make a POST request, the response.body is always a string instead.

client.createTextPost(
    'longblognamethatdoesntexist',
    { body:'hello there' },
    function(err, data, resp) { typeof console.log(resp.body) }
);
> string

client.blogPosts(
    'longblognamethatdoesntexist',
    {},
    function(err, data, resp) { typeof console.log(resp.body) }
);
> object

Ideally it should always be an object, but it is possible that there may be some edge cases (400 or 500 error responses) where the response is not actually JSON as well.

Cannot call method 'get' of undefined (request)

I'm sure I'm doing something wrong, but I can't find a solution. When I try to get some userInfo (as in the example, for testing the code) I always get this error:

Uncaught TypeError: Cannot call method 'get' of undefined bundle.js:199
TumblrClient._get bundle.js:199
TumblrClient.userInfo bundle.js:163
(anonymous function) bundle.js:27
c jquery.js:7341
p.fireWith jquery.js:7403
b.extend.ready jquery.js:6875
H

code on line 199:
request.get({
url: baseURL + path + '?' + qs.stringify(params),
json: true,
oauth: this.credentials,
followRedirect: false
},

I do have valid keys en tokens (i think... :-) )

Any idea what I'm missing?

[Request] More than 20 results.

Premise:
Say I have a blog with 10,000 posts and I want to retrieve all posts with 2 specified tags.
Actions:

  1. I make a query on the first tag (since only search for 1 tag is allowed), and then I check all tag arrays of each returned item to see if they have the second tag.
  2. The each tag have about 1,000 results, but only about 20 posts overlap which have both tags.
  3. My API would make a request per 20 posts, check results, then make a request for the next 20.

You see that we can easily get over 50 API requests will have to be made...

Therefor I want to request for supporting more than only 20 results on a query.

Update unsecure request version

request has a dependency to extend package. And in the version of request, that tumblr depends on, extend has a security warning according to GitHub.

Details of this vulnerability can be seen here: https://nvd.nist.gov/vuln/detail/CVE-2018-16492

I'm suggesting to increase the version number of request dependency. Updating the number from ^2.87.0 to ^2.88.0 should solve the issue. After updating, maybe there should be a patch level version bump also for tumblr.js?

bad responses are crashing my app?

I'm needing to pass everything through a try{} block because nodejs fails in tumblr.js. I'm not sure why it's failing. It's entirely possible that it's because of rate-limiting, as the app itself is a chat bot that posts incoming links to tumblr, but so far it crashes during relatively slow times in the chat room (IE, times when there aren't many links being posted). It would be nice if tumblr.js checked for an error before trying to parse the body...

undefined:1
undefined
^
SyntaxError: Unexpected token u
    at Object.parse (native)
    at Request._callback (/home/efreak/chattr/dev/efreak-git/node_modules/tumblr.js/lib/tumblr.js:178:19)
    at self.callback (/home/efreak/chattr/dev/efreak-git/node_modules/tumblr.js/node_modules/request/main.js:122:22)
    at Request.EventEmitter.emit (events.js:117:20)
    at ClientRequest.self.clientErrorHandler (/home/efreak/chattr/dev/efreak-git/node_modules/tumblr.js/node_modules/request/main.js:225:10)
    at ClientRequest.EventEmitter.emit (events.js:95:17)
    at Socket.socketOnData (http.js:1589:9)
    at TCP.onread (net.js:525:27)
efreak@holistichippo:~/chattr/dev/efreak-git$

Error while posting multiple video post at once

Hii all,

I am working on a project where I am trying to make request to the tumbrl API with the tumblr.js module.

When I make a single post request to the API, post is successfully created. But when I send multiple request at a time, it returns error API error: 403 Forbidden.

This is happening for the video posts only for all the other type of posts there is no issue like that.

Access x-ratelimit* headers in tumblr.js

Is there a way to access the headers from the request tumblr.js makes. I need access to the x-ratelimit headers tumblr sends. I don't believe there's anything that exposes them, and also can't monkey patch easily since it's a privately scoped function.

function requestCallback(callback) {   
  if (!callback) return;  
  return function (err, response, body) {  
    if (err) return callback(err);  
    var ratelimit_headers = {}; 
    for(var key in response.headers) {
      if(key.match(/x-ratelimit/)) { 
        ratelimit_headers[key] = response.headers[key];
      }  
    }
    /* HERES MY RATE LIMIT HEADERS */
    console.log("RATELIMIT HEADERS: ", ratelimit_headers);  
    if (response.statusCode >= 400) { 
      var err = body.meta ? body.meta.msg : body.error; 
      return callback(new Error('API error: ' + response.statusCode + ' ' + err)); 
    } 
    return callback(null, body.response);
  };
}

Can tumblr.js be published pre-compiled ?

Tumblr.js node dependencies don't compile when attempting to compile with Create React App. The issue is summarized below.
Some third-party packages don't compile their code to ES5 before publishing to npm. This often causes problems in the ecosystem because neither browsers (except for most modern versions) nor some tools currently support all ES6 features. We recommend to publish code on npm as ES5 at least for a few more years.

Question about `taggedPosts`

The docs say to get tagged photos:
client.taggedPosts(tag, options, callback);
My questions:

  1. What are the option parameters we are able to feed into options? That wasn't entirely clear from the docs.
  2. I need to see what info the photos in callback will contain. In my case I need to search for multiple tags so get all photos with 1 tag, then in the callback can I see all the tags a photo has per photo?
    Is there any example of a callback somewhere?

get: Followers and Following with options

Hello!
There seems to be an issue with grabbing follower and following data when using options.
I am using client.followers("username", {limit: 5, offset: 0}, function(err, data){}); in a fully authenticated environment. I am able to get all the followers and following up to 20, without the option param, but using it, I am getting the err: [Error: API error: 401 Not Authorized]
I have been unable to get any sort of data for this, do you have any idea what makes it not continue to be authorized?

Support Promise

For the time being, Promise(or async/await) is considered as a right way to handle asynchronous actions. It would be nice if tumblr.js worked with Promise too.

I have read source code of tumblr.js a little bit and found that Promise can be supported quite easily if we set the requestLibrary parameter of the TumblrClient constructor as request-promise. It has compatible APIs with request, so I guess it just works without any modification.

Thus, I think there can be several options.

  1. Just add the guide above to README
  2. Update tumblr.js to alternatively use request-promise as its request-er. If this option looks better, I'm willing to provide a PR.

Please let me know if there is any comment.

Edit method : 401 unauthorized

Hi !
The method edit is not well documented. Here is what I did:

var tumblr = require( 'tumblr.js' );

var oauth = {
    consumer_key   : "my consumer key",
    consumer_secret: "my consumer secret",
    token          : "my token",
    token_secret   : "my token secret"

};

var client = tumblr.createClient( oauth );
// getAllPosts returns an array with all the posts on my blog
getAllPosts().then( function( posts ){
    var p = posts[0]; // I get the first one
    p.tags.push( "lipoulpe" ); // I add a tag
    console.log(p);
    client.edit( BLOGNAME, p, function( err, ok ){
        console.log( "isok " + (!err) );
        console.log( err );
        console.log( ok );
    } )

}, console.log );

The output is always the same:

isok false
[Error: API error: 401 Not Authorized]
undefined

Did I do something wrong or is there a problem with the API ? Did you successfully edit a post (I haven't seen anything related to editing in the tests) ?

Thanks you

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.