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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?
去到頂部