Skip to content
Fanfou SDK for browser
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
.npmrc
.travis.yml
LICENSE
README.md
package.json
webpack.config.js

README.md

fanfou-sdk-browser

Fanfou SDK for browser

Install

$ npm i fanfou-sdk-browser

Usage

import Fanfou from 'fanfou-sdk-browser'

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

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.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: uploadFile, 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')
    }
  }
})

Related

  • x-fan - A Fanfou client with front-end alone
  • fanfou-sdk-node - Fanfou SDK for Node.js
  • fanfou-sdk-weapp - Fanfou SDK for WeApp
  • ky - Tiny and elegant HTTP client based on the browser Fetch API

License

MIT © LitoMore

You can’t perform that action at this time.