Coder Social home page Coder Social logo

fanfou-sdk-python's Introduction

fanfou-sdk-python

Fanfou SDK for Python

Install

pip install fanfou_sdk

Usage

OAuth

from fanfou_sdk import Fanfou

ff = Fanfou(
    consumer_key='',
    consumer_secret='',
    oauth_token='',
    oauth_token_secret=''
)

result, response = ff.get('/statuses/home_timeline', {'format': 'html'})
print(result, response)

XAuth

ff = Fanfou(
  consumer_key='',
  consumer_secret='',
  username='',
  password=''
)

token, response = ff.xauth()
print(token, response)

timeline, _ = ff.get('/statuses/public_timeline', {'count': 10})
print(timeline)

status, _ = ff.post('/statuses/update', {'status': 'Hi Fanfou'})
print(status)

Options

  • consumer_key: The consumer key
  • consumer_secret: The consumer secret
  • oauth_token: The OAuth token
  • oauth_token_secret: The OAuth token secret
  • username: The Fanfou username
  • password: The Fanfou password
  • protocol: Set the prototol, default is http:
  • api_domain: Set the API domain, default is api.fanfou.com
  • oauth_omain: 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.request_token()
ff.access_token(token)
ff.xauth()
ff.get(uri, params={})
ff.post(uri, params={}, files=None)

Examples

# Get request token
token, _ = ff.request_token()
print(token)

# Get access token
token, _ = ff.access_token()
print(token)

# Get timeline
tl, _ = ff.get('/statuses/home_timeline')
print(tl)

# Post status
st, _ = ff.post('/statuses/update', {status: 'hi flora'})
print(st)

# Upload photo
st, _ = ff.post(
  '/photos/upload',
  params={'status': 'unicorn'},
  files={'photo': open('file_path', 'rb')}
)
print(st)

Tips

Use hooks for your reverse-proxy server

ff = Fanfou(
  consumer_key='',
  consumer_secret='',
  oauth_token='',
  oauth_token_secret='',
  api_domain='api.example.com',
  oauth_domain='example.com',
  hooks={
    'base_string': lambda s: s.replace('example.com', 'fanfou.com')
  }
)

Related

License

MIT

fanfou-sdk-python's People

Contributors

litomore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rubinorlando

fanfou-sdk-python's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.