0.8.0 • Published 5 years ago
fanfou-sdk-browser v0.8.0
fanfou-sdk-browser
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 keyconsumerSecret
: The consumer secretoauthToken
: The OAuth tokenoauthTokenSecret
: The OAuth token secretusername
: The Fanfou usernamepassword
: The Fanfou passwordprotocol
: Set the protocol, default is''
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.
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
- fanfou-pro - A Web App Fanfou client
- x-fan - A Fanfou client with Framework7
- fanfou-sdk-node - Fanfou SDK for Node.js
- fanfou-sdk-deno - Fanfou SDK for Deno
- fanfou-sdk-weapp - Fanfou SDK for WeApp
- fanfou-sdk-python - Fanfou SDK for Python
- ky - Tiny and elegant HTTP client based on the browser Fetch API
License
MIT