项目作者: fanfoujs

项目描述 :
Fanfou SDK for WeApp
高级语言: JavaScript
项目地址: git://github.com/fanfoujs/fanfou-sdk-weapp.git
创建时间: 2018-04-17T18:08:31Z
项目社区:https://github.com/fanfoujs/fanfou-sdk-weapp

开源协议:Other

下载


fanfou-sdk-weapp




Fanfou SDK for WeApp

The package is for WeApp, if you are developing with Node.js, please use fanfou-sdk.

Install

  1. $ npm i fanfou-sdk-weapp

Or either of this below:

  • Add this repo as submodule to your project
  • Copy the src directory to your project



Usage

  1. const Fanfou = require('fanfou-sdk-weapp')
  2. // or
  3. const Fanfou = require('./src/index');

OAuth

  1. const ff = new Fanfou({
  2. consumerKey: '',
  3. consumerSecret: '',
  4. oauthToken: '',
  5. oauthTokenSecret: ''
  6. });
  7. ff.get('/statuses/home_timeline', {format: 'html'})
  8. .then(res => console.log(res))
  9. .catch(err => console.log(err));

XAuth

  1. const ff = new Fanfou({
  2. consumerKey: '',
  3. consumerSecret: '',
  4. username: '',
  5. password: ''
  6. });
  7. ff.xauth()
  8. .then(res => {
  9. console.log(res)
  10. ff.get('/statuses/public_timeline', {count: 10})
  11. .then(res => console.log(res))
  12. .catch(err => console.log(err));
  13. ff.post('/statuses/update', {status: 'Hi Fanfou'})
  14. .then(res => console.log(res))
  15. .catch(err => console.log(err));
  16. });

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 prototol, default is https:
  • 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

  1. ff.xauth();
  2. ff.get(uri, params);
  3. ff.post(uri, params);
  4. ff.upload(uri, fileObject, parameters);

Examples

  1. // OAuth
  2. ff.get('/statuses/home_timeline', {})
  3. .then(res => console.log(res))
  4. .catch(err => console.log(err));
  5. ff.post('/statuses/update', {status: 'post test'})
  6. .then(res => console.log(res))
  7. .catch(err => console.log(err));
  8. // Upload
  9. wx.chooseImage({
  10. count: 1,
  11. sizeType: ['original', 'compressed'],
  12. sourceType: ['album', 'camera'],
  13. success: res => {
  14. const {tempFilePaths} = res;
  15. const [fileObject] = tempFilePaths;
  16. ff.upload('/photos/upload', fileObject, {})
  17. .then(res => console.log(res))
  18. .catch(err => console.log(err));
  19. }
  20. });
  21. // XAuth
  22. ff.xauth()
  23. .then(res => {
  24. ff.get('/statuses/public_timeline', {})
  25. .then(res => console.log(res))
  26. .catch(err => console.log(err))
  27. })
  28. .catch(err => console.log(err));

Tips

Use hooks for your reverse-proxy server

  1. const ff = new Fanfou({
  2. consumerKey: '',
  3. consumerSecret: '',
  4. oauthToken: '',
  5. oauthTokenSecret: '',
  6. apiDomain: 'api.example.com',
  7. oauthDomain: 'example.com',
  8. hooks: {
  9. baseString: str => {
  10. return str.replace('example.com', 'fanfou.com');
  11. }
  12. }
  13. });

License

MIT