Skip to content

Commit f9c3dba

Browse files
committed
Create README.md
1 parent 26c06e7 commit f9c3dba

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Medium SDK for Python
2+
3+
This repository contains the open source SDK for integrating
4+
[Medium](https://medium.com/)'s OAuth2 REST API with your Python app.
5+
6+
For full API documentation, see our [developer docs](https://github.com/Medium
7+
/medium-api-docs).
8+
9+
## Usage
10+
11+
```python
12+
from medium import Client
13+
14+
# Contact [email protected] to get your application_kd and application_secret.
15+
client = Client(application_id="MY_APPLICATION_ID", application_secret="MY_APPLICATION_SECRET")
16+
17+
# Build the URL where you can send the user to obtain an authorization code.
18+
auth_url = client.get_authorization_url("secretstate", "https://yoursite.com/callback/medium",
19+
["basicProfile", "publishPost"])
20+
21+
# (Send the user to the authorization URL to obtain an authorization code.)
22+
23+
# Exchange the authorization code for an access token.
24+
auth = client.exchange_authorization_code("YOUR_AUTHORIZATION_CODE",
25+
"https://yoursite.com/callback/medium")
26+
27+
# The access token is automatically set on the client for you after
28+
# a successful exchange, but if you already have a token, you can set it
29+
# directly.
30+
client.access_token = auth["access_token"]
31+
32+
# Get profile details of the user identified by the access token.
33+
user = client.get_current_user()
34+
35+
# Create a draft post.
36+
post = client.create_post(user_id=user["id"], title="Title", content="<h2>Title</h2><p>Content</p>",
37+
content_format="html", publish_status="draft")
38+
39+
# When your access token expires, use the refresh token to get a new one.
40+
client.exchange_refresh_token(auth["refresh_token"])
41+
42+
# Confirm everything went ok. post["url"] has the location of the created post.
43+
print "My new post!", post["url"]
44+
```
45+
46+
## Contributing
47+
48+
Questions, comments, bug reports, and pull requests are all welcomed. If you
49+
haven't contributed to a Medium project before please head over to the [Open
50+
Source Project](https://github.com/Medium/opensource#note-to-external-contributors)
51+
and fill out an OCLA (it should be pretty painless).
52+
53+
## Authors
54+
55+
- [Kyle Hardgrave](https://github.com/kylehg)
56+
57+
## License
58+
59+
Copyright 2015 [A Medium Corporation](https://medium.com/)
60+
61+
Licensed under Apache License Version 2.0. Details in the attached LICENSE file.

0 commit comments

Comments
 (0)