javascript - Tumblr.js API -- require() fails - Stack Overflow

I've been trying to get tumblr.js api to work for about 3 days now on localhost and hosted. My app

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745467790a4628992.html

相关推荐

  • javascript - Tumblr.js API -- require() fails - Stack Overflow

    I've been trying to get tumblr.js api to work for about 3 days now on localhost and hosted. My app

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信