Fanfou SDK for Node.js
$ npm i fanfou-sdk
const Fanfou = require('fanfou-sdk')
OAuth
const ff = new Fanfou({
consumerKey: '',
consumerSecret: '',
oauthToken: '',
oauthTokenSecret: ''
});
ff.get('/statuses/home_timeline', {format: 'html'})
.then(res => console.log(res))
.catch(res => console.log(err));
XAuth
const ff = new Fanfou({
consumerKey: '',
consumerSecret: '',
username: '',
password: ''
});
ff.xauth()
.then(res => {
console.log(res);
ff.get('/statuses/public_timeline', {count: 10})
.then(res => console.log(res))
.catch(err => console.log(err));
ff.get('/statuses/update', {status: 'Hi Fanfou'})
.then(res => console.log(res))
.catch(err => console.log(err));
})
.catch(err => console.log(err));
For more usages, see the example.
Options
consumerKey
: The consumer keyconsumerSecret
: The consumer secretoauthToken
: The OAuth tokenoauthTokenSecret
: The OAuth token secretusername
: The Fanfou usernamepassword
: The Fanfou passwordprotocol
: Set the prototol, default ishttp:
fakeHttps
: A hook to replace the OAuth basestring, default isfalse
apiDomain
: Set the API domain, default isapi.fanfou.com
oauthDomain
: Set the OAuth domain, default isfanfou.com
hooks
: Hooks allow modifications with OAuth
For more Fanfou API docs, see the Fanfou API doc.
ff.xauth();
ff.get(uri, params);
ff.post(uri, params);
ff.upload(uri, params);
Examples
ff.get('/statuses/home_timeline', {})
.then(res => console.log(res))
.catch(err => console.log(err));
ff.post('/statuses/update', {status: 'post test'})
.then(res => console.log(res))
.catch(err => console.log(err));
ff.upload('/photos/upload', {photo: fs.createReadStream(path), status: 'unicorn'})
.then(res => console.log(res))
.catch(err => console.log(err));
Tips
Use hooks
for your reverse-proxy server
const ff = new Fanfou({
consumerKey: '',
consumerSecret: '',
oauthToken: '',
oauthTokenSecret: '',
apiDomain: 'api.example.com',
oauthDomain: 'example.com',
hooks: {
baseString: str => {
return str.replace('example.com', 'fanfou.com')
}
}
});
Example
import * as Fanfou from 'fanfou-sdk';
const opt: Fanfou.FanfouOptions = {
consumerKey: '',
consumerSecret: '',
oauthToken: '',
oauthTokenSecret: '',
}
const ff = new Fanfou(opt);
ff.post('/user_timeline', {count: 10});
For more declarations, see the declaration file.
- nofan - CLI for Fanfou
- xiaofan - WeApp for Fanfou
- fanfou-streamer - Fanfou Streaming SDK for Node.js
- fanfou-sdk-browser - Fanfou SDK for browser
- fanfou-sdk-weapp - Fanfou SDK for WeApp
- alfred-fanfou - Alfred 3 workflow for Fanfou
- kap-fanfou - Kap plugin that share on Fanfou
- cerebro-fanfou - A cerebro plugin for Fanfou
MIT © LitoMore