Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelliao committed Feb 24, 2014
1 parent 8f7201a commit 7b4408a
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
# Sinaweibopy
# snspy

SNSPY is a stand-alone Python script which provides

A stand-alone Python script which provides
* OAuth2.0 authentication
* API calling wrapper


for any social network providers.

http://michaelliao.github.com/sinaweibopy/

Developed and mantained by Michael Liao. Please feel free to report bugs and
your suggestions at [here](https://github.com/michaelliao/sinaweibopy).

## OAuth2.0

After setting up your [Open Weibo Account](http://open.weibo.com) and
registering for an application, you will receive `YOUR_APP_KEY` and
`YOUR_APP_SECRET`. Together with `YOUR_CALLBACK_URL`, these are the environment
variables required by sinaweibopy.
OAuth 2 is a protocol focuses on client developer simplicity while providing
specific authorization flows for web applications.

There are many social networks provides OAuth 2 authentication and APIs, and
snspy is a simple API wrapper for any social network such as Twitter, Facebook,
LinkedIn, Sina Weibo, etc.

snspy provides a unique API interface for developers and difference of each
social network APIs are handled by its `mixin`.

## Basic Usage

You need to register your OAuth 2 application on the social network you choose:

[Tweeter]()
[Facebook]()
[LinkedIn]()
[Sina Weibo]()
[QQ Connect]()

After setting up your account and registering for an application, you will receive
`YOUR_APP_KEY` and `YOUR_APP_SECRET`. Together with `YOUR_CALLBACK_URL`, these are
the environment variables required by snspy. And you can create the APIClient now:

```python
from weibo import APIClient

from snspy import APIClient
from snspy import TwitterMixin # suppose you are using Twitter

APP_KEY = 'YOUR_APP_KEY' # app key
APP_SECRET = 'YOUR_APP_SECRET' # app secret
CALLBACK_URL = 'YOUR_CALLBACK_URL' # callback url

client = APIClient(TwitterMixin, app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
```

Put on your website a link which redirect the user to the following
authorization URL:

```python
client = APIClient(app_key=YOUR_APP_KEY, app_secret=YOUR_APP_SECRET,
redirect_uri=YOUR_CALLBACK_URL)
url = client.get_authorize_url() # redirect the user to `url'
url = client.get_authorize_url() # redirect the user to 'url'
```

After granting the privileges, the user will be redirected to
Expand All @@ -39,8 +63,16 @@ get the access token using this `SOME_CODE`.
```python
r = client.request_access_token(SOME_CODE)
access_token = r.access_token # access token,e.g., abc123xyz456
expires_in = r.expires_in # token expires in
client.set_access_token(access_token, expires_in)
expires = r.expires # token expires time, UNIX timestamp, e.g., 1384826449.252 (10:01 am, 19 Nov 2013, UTC+8:00)
NOTE: you should store the access_token for later use.
```

After got access token you can init the APIClient any time:

```python
client = APIClient(TwitterMixin,
app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL,
access_token=YOUR_ACCESS_TOKEN, expires=EXPIRES_TIME)
```

Then, you are free to call whatever API you like. For example,
Expand Down

0 comments on commit 7b4408a

Please sign in to comment.