help with tumblr.js for a newbie

2,775 views
Skip to first unread message

Matthew

unread,
Mar 15, 2013, 10:34:08 AM3/15/13
to tumbl...@googlegroups.com
Hi all,

Please forgive my ignorance but I'm literally just starting to learn Javascript. What I'm just trying to do right now is download the tumblr.js code (https://github.com/tumblr/tumblr.js) and get it to run. Here's the code I have so far:

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

client.userInfo(function (err, data) { data.blogs.forEach(function (blog) { console.log(blog.name); }); });


This is just how it's set up in the README. However, when I run the code I get an error saying that request.get is not found on 'undefined' (that's not the exact wording).
I understand why this error occurs - in /bin/tumblr.js var request is defined (line 8) but never initialised and it's trying to use request.get on line 162.
I see that you can initialise it sort of like we initialised client above but I have no idea about how to do that or what I'm supposed to initialise it to.
Am I just missing something simple or am I not understanding something on a deeper level? I don't really understand what the
modules.exports 'object' is either. Again, sorry for my ignorance but I'm just learning this stuff.

FYI, I do have a valid consumer key/secret as well as oauth token/secret. I've also installed node.js.

Thanks so much for any help you can provide!

John Crepezzi

unread,
Mar 15, 2013, 10:42:45 AM3/15/13
to tumbl...@googlegroups.com
If you download the tumblr code instead of pulling it in from `npm`, you need to require('path/to/it/index.js'), not tumblr.js
hope this helps!

Matthew

unread,
Mar 15, 2013, 11:21:33 AM3/15/13
to tumbl...@googlegroups.com
Ah, that makes sense and that helped a little bit! But now I'm getting a different error saying that it can't find the module 'request'. Here's the trace:

module.js:340
    throw err;
          ^
Error: Cannot find module 'request'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (<PATH REDACTED>/github/tumblr.js/index.js:2:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Any help with this one? And I didn't quite have the right code before (I didn't have access to the file and was going off of memory). The actual code is below.

This is a file that I've called tumblrpractice.js and is in the root directory of the tumbr.js folder I downloaded from Github.

var tumblr = require('./index.js');
var client = tumblr.createClient({
  consumer_key: '<REDACTED>',
  consumer_secret: '<REDACTED',
  token: '<REDACTED>',
  token_secret: '<REDACTED>'
});

client.blogInfo('<BLOG NAME>.tumblr.com', function (err, data) {
    data.blogs.forEach(function (blog) {
        console.log(blog.name);
    });
});

Thanks!

John Crepezzi

unread,
Mar 15, 2013, 11:25:29 AM3/15/13
to tumbl...@googlegroups.com
Run `npm install`.

Matthew

unread,
Mar 15, 2013, 1:31:45 PM3/15/13
to tumbl...@googlegroups.com
Yup! Looks like I was just missing the request package in my tumblr.js folder. I just had to navigate to that folder in Terminal and run `npm install request`.

Thanks so much!

John Crepezzi

unread,
Mar 15, 2013, 1:34:50 PM3/15/13
to tumbl...@googlegroups.com
npm install would cover you - installs all packages that are listed as dependencies in package.json
thanks!

Matthew

unread,
Mar 15, 2013, 1:39:30 PM3/15/13
to tumbl...@googlegroups.com
Good to know, thanks!

Matthew

unread,
Mar 15, 2013, 2:12:31 PM3/15/13
to tumbl...@googlegroups.com
I hope you don't mind me bugging you some more. I was able to successfully use the blogInfo and userInfo methods. However, I can't figure out what I'm not doing correctly on the text(blogName, options, callback) method?

Here's my code:
client.text('matthewjanssen', { title: 'This is a test',
                                body: 'This is a test of the tumblr javascript API',
                                tweet: 'off',
                                format: 'markdown',
                                tags: 'comma, separated, list, of, tags'}, function (err, success) {
    console.log(success);
});

I'm thinking my options object isn't correct. On line 173 of /lib/tumblr.js the var data ends up being undefined. I printed params directly to the console and everything's there (as shown above) but apparently params.data doesn't get anything...

Thanks for being so patient as I'm learning this.

John Crepezzi

unread,
Mar 15, 2013, 2:47:06 PM3/15/13
to tumbl...@googlegroups.com
No problem - `data` is only for photo, audio & video posts - since the client has to send file-type components slightly different
What error are you seeing?

Matthew

unread,
Mar 15, 2013, 3:44:47 PM3/15/13
to tumbl...@googlegroups.com
Ah, ok the `data` makes sense.
Well, I'm not really getting an error (that I can see). It's just that the console.log(success) prints undefined. And the post isn't making it all the way through because I don't see it on my blog. But other than that, I don't get an error.

John Crepezzi

unread,
Mar 15, 2013, 3:58:33 PM3/15/13
to tumbl...@googlegroups.com
Does console.log(err) show something? :)


--
You received this message because you are subscribed to the Google Groups "Tumblr API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tumblr-api+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Matthew

unread,
Mar 15, 2013, 5:49:54 PM3/15/13
to tumbl...@googlegroups.com
API error: 401 Not Authorized.
Well, I never really went through a procedure to get my oauth_token and oauth_token_secret. So I guess what I'm using is invalid. And OAuth is something that I know even less about than what I'm doing now.

Thanks.

John Crepezzi

unread,
Mar 15, 2013, 5:54:15 PM3/15/13
to tumbl...@googlegroups.com
Cool - let us know if you have more questions;
It's fairly easy to use the ruby client at https://github.com/codingjester/tumblr_client to generate yourself a token and secret

gem install tumblr_client
bin/tumblr # follow the flow
cat ~/.tumblr # look at the keys

Matthew

unread,
Mar 15, 2013, 8:36:11 PM3/15/13
to tumbl...@googlegroups.com
Holy macaroni! I finally got it working! I can't thank you enough for all of your help!

Jerry Mo

unread,
Aug 19, 2013, 4:00:21 PM8/19/13
to tumbl...@googlegroups.com
I am new to this API.

I got a error message:

ReferenceError: require is not defined
var tumblr = require('https://npmjs.org/package/tumblr.js');

Is there some one can help, thanks

Jerry

Jonathanmv

unread,
Dec 14, 2013, 9:45:38 AM12/14/13
to tumbl...@googlegroups.com
You need to run the examples from a nodejs environment like node console
Reply all
Reply to author
Forward
Message has been deleted
0 new messages