From 083299d3e64b4bc2dfe74f717e9e49f09d6246b2 Mon Sep 17 00:00:00 2001 From: zealotce Date: Wed, 11 Oct 2017 12:10:08 +0800 Subject: [PATCH 1/4] =?UTF-8?q?delete=20README.tst=20add=20README.md,beacu?= =?UTF-8?q?se=20python3.6=20pip=20install=20weibo=20error:'gbk'=20codec=20?= =?UTF-8?q?can=20not=20decode=20byte=200xae=20in=20position.=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=BA=86=20README.rst=20=E6=B7=BB=E5=8A=A0=E4=BA=86RE?= =?UTF-8?q?ADME.md=20,=E5=9B=A0=E4=B8=BApython3=20=E4=B8=8Apipinstall=20we?= =?UTF-8?q?ibo=20=E5=87=BA=E7=8E=B0=E9=94=99=E8=AF=AF=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.rst => README.md | 75 +++++++++++++++++++---------------------- weibo.py | 6 ++-- 2 files changed, 37 insertions(+), 44 deletions(-) rename README.rst => README.md (52%) diff --git a/README.rst b/README.md similarity index 52% rename from README.rst rename to README.md index 40c3c2f..0873a97 100644 --- a/README.rst +++ b/README.md @@ -1,11 +1,9 @@ Weibo ===== -.. image:: http://img.shields.io/pypi/v/weibo.svg?style=flat - :target: https://pypi.python.org/pypi/weibo +[![](http://img.shields.io/pypi/v/weibo.svg?style=flat"mylib")](https://pypi.python.org/pypi/weibo) -.. image:: http://img.shields.io/pypi/dm/weibo.svg?style=flat - :target: https://pypi.python.org/pypi/weibo +[![](http://img.shields.io/pypi/dm/weibo.svg?style=flat)](https://pypi.python.org/pypi/weibo) 新浪微博 python SDK. @@ -18,16 +16,15 @@ Weibo 推荐使用 `pip` 安装。 -.. code:: bash - - $ pip install weibo - +``` bash +pip install weibo +``` 使用说明 -------- -准备工作 -~~~~~~~~ +###准备工作 + - 首先,注册一个新浪开发者帐号,并在 `新浪开发平台 `_ 新建一个 app. @@ -35,61 +32,59 @@ Weibo - 在 '应用信息 -> '高级信息' 里面设置好 '授权回调页'. -示例 -~~~~ +###示例 + 下面分别用 `API_KEY`, `API_SECRET`, `REDIRECT_URI` 代表准备工作里面的三个参数。 Token 认证 -"""""""""" -.. code:: python - >>> from weibo import Client - >>> c = Client(API_KEY, API_SECRET, REDIRECT_URI) - >>> c.authorize_url - 'https://api.weibo.com/oauth2/authorize?redirect_uri=http%3A%2F%2F127.0.0.1%2Fcallback&client_id=123456' +```python +>>> from weibo import Client +>>> c = Client(API_KEY, API_SECRET, REDIRECT_URI) +>>> c.authorize_url +'https://api.weibo.com/oauth2/authorize?redirect_uri=http%3A%2F%2F127.0.0.1%2Fcallback&client_id=123456' +``` 复制链接到浏览器打开,获取 code. -.. code:: python - - >>> c.set_code('abcdefghijklmn') - +``` python +>>> c.set_code('abcdefghijklmn') +``` client 初始化完成。token 可以被保存下来供下次调用时直接使用。 -.. code:: python +```python +>>> token = c.token +>>> c2 = Client(API_KEY, API_SECRET, REDIRECT_URI, token) +>>> c2.get('users/show', uid=2703275934) +``` - >>> token = c.token - >>> c2 = Client(API_KEY, API_SECRET, REDIRECT_URI, token) - >>> c2.get('users/show', uid=2703275934) +###帐号认证 -帐号认证 -"""""""" 除了使用 token 认证,还可以使用 username / password 进行认证。 -.. code:: python +```python >>> from weibo import Client >>> c = Client(API_KEY, API_SECRET, REDIRECT_URI, username='admin', password='secret') >>> c.get('users/show', uid=1282440983) +``` +###接口调用 -接口调用 -"""""""" 参考 `微博开发文档 `_ 进行接口调用。 -.. code:: python - - >>> c.get('users/show', uid=1282440983) - >>> c.post('statuses/update', status='python sdk test, check out http://lxyu.github.io/weibo/') - +```python +>>> c.get('users/show', uid=1282440983) +>>> c.post('statuses/update', status='python sdk test, check out http://lxyu.github.io/weibo/') +``` client 兼容上传图片接口。 -.. code:: python - - >>> f = open('avatar.png', 'rb') - >>> c.post('statuses/upload', status='new avatar!', pic=f) +````python +>>> f = open('avatar.png', 'rb') +>>> c.post('statuses/upload', status='new avatar!', pic=f) +```` \ No newline at end of file diff --git a/weibo.py b/weibo.py index 0b1bd45..6a5eb6b 100644 --- a/weibo.py +++ b/weibo.py @@ -11,10 +11,8 @@ from __future__ import absolute_import -try: - from urllib.parse import urlencode -except ImportError: - from urllib import urlencode +from urllib.parse import urlencode + import json import time From f6542d2cefd9f63b292d9d1bceaffaa286845438 Mon Sep 17 00:00:00 2001 From: zealotce Date: Wed, 11 Oct 2017 12:15:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?delete=20README.tst=20add=20README.md,beacu?= =?UTF-8?q?se=20python3.6=20pip=20install=20weibo=20error:'gbk'=20codec=20?= =?UTF-8?q?can=20not=20decode=20byte=200xae=20in=20position.=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=BA=86=20README.rst=20=E6=B7=BB=E5=8A=A0=E4=BA=86RE?= =?UTF-8?q?ADME.md=20,=E5=9B=A0=E4=B8=BApython3=20=E4=B8=8Apipinstall=20we?= =?UTF-8?q?ibo=20=E5=87=BA=E7=8E=B0=E9=94=99=E8=AF=AF=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weibo.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/weibo.py b/weibo.py index 6a5eb6b..0b1bd45 100644 --- a/weibo.py +++ b/weibo.py @@ -11,8 +11,10 @@ from __future__ import absolute_import -from urllib.parse import urlencode - +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode import json import time From dfa5024fba8ee737213d9a80162ade60b9e4567d Mon Sep 17 00:00:00 2001 From: zealotce Date: Wed, 11 Oct 2017 12:22:23 +0800 Subject: [PATCH 3/4] Signed-off-by: zealotce --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0873a97..0a51794 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ client 初始化完成。token 可以被保存下来供下次调用时直接使 ###接口调用 -参考 `微博开发文档 `_ 进行接口调用。 +参考 [微博开发文档](http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2) 进行接口调用。 ```python >>> c.get('users/show', uid=1282440983) From b25a02954dd09a87c50275dbfe386765116a6aa8 Mon Sep 17 00:00:00 2001 From: zealotce Date: Wed, 11 Oct 2017 12:31:18 +0800 Subject: [PATCH 4/4] delete README.rst add README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a51794..4b7ccbc 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ pip install weibo 下面分别用 `API_KEY`, `API_SECRET`, `REDIRECT_URI` 代表准备工作里面的三个参数。 -Token 认证 +###Token 认证 ```python