• Stars
    star
    1,274
  • Rank 35,886 (Top 0.8 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 12 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

新浪微博Python SDK

snspy

SNSPY is 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.

OAuth2.0

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:

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:

url = client.get_authorize_url()    # redirect the user to 'url'

After granting the privileges, the user will be redirected to YOUR_CALLBACK_URL, with parameter code=SOME_CODE attached. Then you need to get the access token using this SOME_CODE.

r = client.request_access_token(SOME_CODE)
access_token = r.access_token  # access token,e.g., abc123xyz456
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:

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,

print client.statuses.user_timeline.get()
print client.statuses.update.post(status=u'test plain weibo')
print client.statuses.upload.post(status=u'test weibo with picture',
                                  pic=open('/Users/michael/test.png'))

How to call a particular API

Firstly, refer to the corresponding API document. Use user_timeline as an example:

API:
statuses/user_timeline

HTTP Request Method:
GET

Request Parameters:
source:       string, This parameter is not needed when using OAuth. The value
                      of this parameter is the AppKey.
access_token: string, This parameter is required when using OAuth.You will get
                      the access_token after oauth authorization. 
uid:          int64,  Return the weibos of specified ID of a user. 
screen_name:  string, The nickname of the user that ID is specified. 

Substitute / in the API with ., and call get() or post() according to the request method with all the necessary parameters excluding source and access_token.

r = client.statuses.user_timeline.get(uid=SOME_ID)
for st in r.statuses:
    print st.text

If the request method is POST, then it should be something like the following:

r = client.statuses.update.post(status=u'test weibo')

And, as for uploading pictures:

f = open('/Users/michael/test.png', 'rb')
r = client.statuses.upload.post(status=u'test weibo with picture', pic=f)
f.close()  # you need to do this manually

Please notice that what is uploaded must be a file-like object. str can be wrapped using StringIO.

wiki

For more information, please refer to the wiki.

More Repositories

1

learn-python3

Learn Python 3 Sample Code
6,013
star
2

awesome-python3-webapp

小白的Python入门教程实战篇:网站+iOS App源码→ http://t.cn/R2PDyWN 赞助→ http://t.cn/R5bhVpf
2,299
star
3

awesome-python-webapp

小白的Python入门教程实战篇:网站+iOS App源码
2,143
star
4

learn-javascript

JavaScript全栈教程参考源码
1,696
star
5

itranswarp.js

Deprecated. See https://github.com/michaelliao/itranswarp
JavaScript
1,409
star
6

cryptocurrency

Simple Java library to interact with bitcoin
JavaScript
835
star
7

itranswarp

Full-featured CMS including blog, wiki, discussion, etc. Cloud native application that powered by SpringBoot.
Java
713
star
8

shici

中华诗词网站 www.shi-ci.com 诗词文件及源码
JavaScript
466
star
9

learn-python

小白的Python入门教程:部分章节源码
Python
448
star
10

learngit

教程→ https://www.liaoxuefeng.com/wiki/896043488029600 推送请使用UTF-8编码
406
star
11

compiler

In-memory compile java source code and load compiled classes.
Java
357
star
12

springcloud

JavaScript
221
star
13

warpexchange

A simple, super fast, 7x24 exchange.
Java
182
star
14

githubpy

A simple GitHub REST API SDK for Python3
Python
135
star
15

remote-code-runner

A remote code running service.
Python
130
star
16

jsonstream

A fast streaming parser for JSON. Learn how to design:
Java
114
star
17

openweixin

可能是最好用的微信公众号Java开发包
CSS
107
star
18

learn-sql

Java
100
star
19

summer-framework

Summer framework is a minimal Spring framework.
Java
84
star
20

miniweibo

使用Python开发的基于新浪微博API的迷你微博网站
Python
81
star
21

warpdb

DSL-driven RDBMS interface for Java.
Java
79
star
22

simple-match-engine

A simple, fast match engine for trading
Java
44
star
23

transwarp

A simple Python framework for web, db and mail.
Python
42
star
24

learn-verilog

Learn Verilog
Verilog
29
star
25

red-packet-contract

Crypto red packet with zk-proof.
HTML
28
star
26

simple-trading-engine

Java
27
star
27

how-to-become-rich

A sample Maven repo that makes you rich.
Java
26
star
28

algorithms

Java
18
star
29

tts

A simple TextToSpeech desktop application based on Microsoft Speech SDK.
Java
15
star
30

cljweb

A clojure web project for start
Clojure
13
star
31

virtual-keyboard

Virtual keyboard is a simulated keyboard with RS-232 serial port support.
C#
12
star
32

mysql-warp

Fast, simple ORM for mysql on Node.js
JavaScript
12
star
33

vote-dapp

Simple dapp for Ethereum
HTML
12
star
34

irunning

iRunning scans your weibo and creates your running report automatically.
Python
11
star
35

periodic-table

Periodic Table / 元素周期表
HTML
11
star
36

mnist

A mnist demo app.
Python
11
star
37

rtmp-livestreaming

Forked from http://code.google.com/p/rtmplite/
Python
11
star
38

crypto-tele-bot

A telegram bot to track crypto market
Java
9
star
39

simple-nft

A simple EIP-1155 based NFT tool.
HTML
9
star
40

blockchain-lib

Generate client-side library for blockchain
JavaScript
9
star
41

learn-english-word

HTML
8
star
42

chatbot

Chat bot driven by AI.
HTML
8
star
43

jxrest

Simple, lightweight Java REST framework
Java
8
star
44

contract-deployer

A contract deployer that support deploy contract with user-defined prefix. e.g. 0xCafe
HTML
8
star
45

es-wrapper

Wrapper for Elastic Search
Java
7
star
46

git-explorer

File explorer for a subdir of repo which can embedded to web page.
JavaScript
7
star
47

jhtml5player

HTML 5 Player on jQuery
JavaScript
7
star
48

eth-smt

Sparse Merkle Tree for Ethereum
Java
7
star
49

oauth2-warp

A simple, fast OAuth2 library for Nodejs.
JavaScript
7
star
50

learn-docker

Python
7
star
51

llm-embedding-sample

LLM Embedding Sample App using Flask and PostgreSQL with pgvector extension.
HTML
6
star
52

nft-generator

Generate NFTs
6
star
53

www-start-script

A simple script to start a www server for static resources.
HTML
5
star
54

1024pixels

Create 32 x 32 = 1024 pixels art as NFT on Polygon blockchain.
HTML
5
star
55

michaelliao.github.com

Michael Liao @ GitHub
CSS
4
star
56

jexieditor

Automatically exported from code.google.com/p/jexieditor
Java
4
star
57

cryptoexchange

4
star
58

web3stack

A demo for Web3 stack.
HTML
4
star
59

simple-assets

Java
4
star
60

jerrymouse

Jerrymouse is a mini version of Tomcat.
Java
4
star
61

weather-china

Automatically exported from code.google.com/p/weather-china
Python
4
star
62

awesome-nodejs-webapp

4
star
63

githubpy-test

Test repo for githubpy, updated at 2023-01-22 18:15
3
star
64

download

Free downloads
3
star
65

complex

A sample maven project for deploy test
Java
3
star
66

gitskills

3
star
67

warpchain

Java
3
star
68

gitdocs

Generate Docs by Git Repo
HTML
3
star
69

kof-chrome-theme

The King of Fighters Theme for Chrome.
3
star
70

michaelliao

Github profile page
HTML
3
star
71

serial-send-image

C#
2
star
72

ssi-server

Server-Side-Includes Server & Generate Static Pages.
HTML
2
star
73

netlify-static

Deploy static website to netlify.
JavaScript
2
star
74

stablecoin-simulator

Algorithmic stable coin simulator
2
star
75

livebookstore

Automatically exported from code.google.com/p/livebookstore
Java
2
star
76

netlify-avatar

Generate GitHub-like avatar by netlify functions.
JavaScript
2
star
77

airdrop-contract

Airdrop contract that support millions of airdrops on ETH-compatible chain.
2
star
78

maven-packages

2
star
79

webwind

(Deprecated) Automatically exported from code.google.com/p/webwind
HTML
2
star
80

compostable-nft

A compostable, lower gas cost NFT solution.
2
star
81

jsonstream-doc

jsonstream documentation
Python
2
star
82

wechatbot

Bot for WeChat
1
star
83

jxrest-doc

jxrest documentation
Python
1
star
84

locking-vault-contract

Lock tokens with linear release.
HTML
1
star
85

image-processor

In-browser image processor, no server-side logic.
HTML
1
star