0.8.0 • Published 5 years ago

fanfou-sdk-browser v0.8.0

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

fanfou-sdk-browser

npm.io npm.io npm.io npm.io

Fanfou SDK for browser

Install

$ npm i fanfou-sdk-browser

Usage

import Fanfou from 'fanfou-sdk-browser'

OAuth

(async () => {
  const ff = new Fanfou({
    consumerKey: '',
    consumerSecret: '',
    oauthToken: '',
    oauthTokenSecret: ''
  })

  const timeline = await ff.get('/statuses/home_timeline', {format: 'html'})
})();

XAuth

(async () => {
  const ff = new Fanfou({
    consumerKey: '',
    consumerSecret: '',
    username: '',
    password: ''
  });

  await ff.xauth();

  const publimeTimeline = await ff.get('/statuses/public_timeline', {count: 10})
  const status = await ff.post('/statuses/update', {status: 'Hi Fanfou'})
})();

Options

  • consumerKey: The consumer key
  • consumerSecret: The consumer secret
  • oauthToken: The OAuth token
  • oauthTokenSecret: The OAuth token secret
  • username: The Fanfou username
  • password: The Fanfou password
  • protocol: Set the protocol, default is ''
  • apiDomain: Set the API domain, default is api.fanfou.com
  • oauthDomain: Set the OAuth domain, default is fanfou.com
  • hooks: Hooks allow modifications with OAuth

For more Fanfou API docs, see the Fanfou API doc.

API

ff.getRequestToken()
ff.getAccessToken(token)
ff.xauth()
ff.get(uri, params)
ff.post(uri, params)
ff.upload(uri, params)

Examples

(async () => {
  // Get request token
  const token = await ff.getRequestToken();

  // Get access token
  const token = await ff.getAccessToken({oauthToken: '', oauthTokenSecret: ''});

  // Get timeline
  const timeline = await ff.get('/statuses/home_timeline', {});

  // Post status
  const status = await ff.post('/statuses/update', {status: 'post test'});

  // Upload photo
  const result = await ff.upload('/photos/upload', {photo: uploadFile, status: 'unicorn'});
})();

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')
    }
  }
})

Related

License

MIT

0.8.0

5 years ago

0.7.0

5 years ago

0.5.0

5 years ago

0.6.0

5 years ago

0.4.0

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago