tumblr / tumblr.js

JavaScript client for the Tumblr API
https://tumblr.github.io/tumblr.js/
Apache License 2.0
647 stars 120 forks source link

client.userFollowing is returning empty blogs despite blogs being followed #80

Closed balupton closed 5 years ago

balupton commented 6 years ago

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?

shahkashani commented 5 years ago

There's a setting that enables/disables access to the follower list, which also affects the information that is made available through the API. You need to toggle this on:

screen shot 2019-02-21 at 11 19 56 am

shahkashani commented 5 years ago

Let me know if that doesn't work and we'll reopen the issue!