medium-sdk-python

Python SDK for Medium's OAuth2 API

  • 所有者: Medium/medium-sdk-python
  • 平台:
  • 许可证: Other
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Warning: This code is no longer supported or maintained by Medium.

Medium SDK for Python

This repository contains the open source SDK for integrating
Medium's OAuth2 REST API with your Python app.

For full API documentation, see our developer docs.

Installing dependencies

To install dependencies using pip:

pip install -r requirements.txt

Usage

from medium import Client

# Go to http://medium.com/me/applications to get your application_id and application_secret.
client = Client(application_id="MY_APPLICATION_ID", application_secret="MY_APPLICATION_SECRET")

# Build the URL where you can send the user to obtain an authorization code.
auth_url = client.get_authorization_url("secretstate", "https://yoursite.com/callback/medium",
                                        ["basicProfile", "publishPost"])

# (Send the user to the authorization URL to obtain an authorization code.)

# Exchange the authorization code for an access token.
auth = client.exchange_authorization_code("YOUR_AUTHORIZATION_CODE",
                                          "https://yoursite.com/callback/medium")

# The access token is automatically set on the client for you after
# a successful exchange, but if you already have a token, you can set it
# directly.
client.access_token = auth["access_token"]

# Get profile details of the user identified by the access token.
user = client.get_current_user()

# Create a draft post.
post = client.create_post(user_id=user["id"], title="Title", content="<h2>Title</h2><p>Content</p>",
                          content_format="html", publish_status="draft")

# When your access token expires, use the refresh token to get a new one.
client.exchange_refresh_token(auth["refresh_token"])

# Confirm everything went ok. post["url"] has the location of the created post.
print "My new post!", post["url"]

Running tests

To run tests against this package, first install the test requirements and make
sure that the medium package is exportable. (We recommend using virtualenv.)

$ pip install -r tests/requirements.txt
$ pip install -e .

Then run the primary test file:

$ python tests/test.py

Contributing

Questions, comments, bug reports, and pull requests are all welcomed. If you
haven't contributed to a Medium project before please head over to the Open
Source Project

and fill out an OCLA (it should be pretty painless).

Authors

License

Copyright 2015 A Medium Corporation

Licensed under Apache License Version 2.0. Details in the attached LICENSE file.

概览

名称与所有者Medium/medium-sdk-python
主编程语言Python
编程语言Python (语言数: 1)
平台
许可证Other
发布数3
最新版本名称v0.3.0 (发布于 )
第一版名称v0.1 (发布于 )
创建于2015-10-01 20:45:29
推送于2024-03-26 00:23:08
最后一次提交2018-10-30 11:21:02
星数189
关注者数143
派生数26
提交数20
已启用问题?
问题数0
打开的问题数0
拉请求数6
打开的拉请求数3
关闭的拉请求数1
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?
去到顶部