admin管理员组

文章数量:1426066

I've been trying to get tumblr.js api to work for about 3 days now on localhost and hosted. My app and keys are valid since I was able to access it with php. This is the readme.md example provided from .js with changes provided by reviewing !topicsearchin/tumblr-api/tumblr.js/tumblr-api/gz8Zv-Mhex4.

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

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

Using firebug, I find that require is not defined selecting require('index.js') as the issue. index.js holds:

     var tumblr = require('lib/tumblr');
     tumblr.request(require('request'));
     module.exports = tumblr;

Upon plete failure I've search online and reviewed countless articles, blogs and posts to no avail. Where am I messing up at? I want to use the api with minimal or no work-around.

I've been trying to get tumblr.js api to work for about 3 days now on localhost and hosted. My app and keys are valid since I was able to access it with php. This is the readme.md example provided from https://github./tumblr/tumblr.js with changes provided by reviewing https://groups.google./forum/#!topicsearchin/tumblr-api/tumblr.js/tumblr-api/gz8Zv-Mhex4.

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

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

Using firebug, I find that require is not defined selecting require('index.js') as the issue. index.js holds:

     var tumblr = require('lib/tumblr');
     tumblr.request(require('request'));
     module.exports = tumblr;

Upon plete failure I've search online and reviewed countless articles, blogs and posts to no avail. Where am I messing up at? I want to use the api with minimal or no work-around.

Share Improve this question asked Aug 29, 2013 at 15:02 TechnoNoobTechnoNoob 314 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

I guess this question is irrelevant now, but I'll answer anyway for anyone ing across this.

I've dealt with this issue as well, and I'm guessing you're trying to do this in the browser. The Tumblr API requires a Node.js installation, which then implements the require() function.

Tumblr.js is for node.js, not in-browser javascript. You can use Tumblr's API via AJAX, normally.

For example, using jQuery you can pull up to 12 photo posts tagged #meme:

$.getJSON('http://api.tumblr./v2/blog/YOURBLOG.tumblr./posts/photo?callback=?', {
    api_key: 'YOUR_API_KEY',
    tag: 'meme',
    limit: 12
}).then(function (json) {
    //do something
});

You can get an API key from Tumblr

本文标签: javascriptTumblrjs APIrequire() failsStack Overflow