|
1 | 1 | imgurpython |
2 | 2 | =========== |
3 | 3 |
|
4 | | -A Python client for the [Imgur API](http://api.imgur.com/). Also includes a friendly demo application. It can be used to |
| 4 | +A Python client for the [Imgur API](http//api.imgur.com/). Also includes a friendly demo application. It can be used to |
5 | 5 | interact with the Imgur API and examine its responses, as a command line utility, and it can be used as a library |
6 | 6 | within your projects. |
7 | 7 |
|
8 | | -You must [register](http://api.imgur.com/oauth2/addclient) your client with the Imgur API, and provide the Client-ID to |
9 | | -make *any* request to the API (see the [Authentication](https://api.imgur.com/#authentication) note). If you want to |
| 8 | +You must [register](http//api.imgur.com/oauth2/addclient) your client with the Imgur API, and provide the Client-ID to |
| 9 | +make *any* request to the API (see the [Authentication](https//api.imgur.com/#authentication) note). If you want to |
10 | 10 | perform actions on accounts, the user will have to authorize your application through OAuth2. |
11 | 11 |
|
12 | 12 | Imgur API Documentation |
13 | 13 | ----------------------- |
14 | 14 |
|
15 | | -Our developer documentation can be found [here](https://api.imgur.com/). |
| 15 | +Our developer documentation can be found [here](https//api.imgur.com/). |
16 | 16 |
|
17 | 17 | Community |
18 | 18 | --------- |
19 | 19 |
|
20 | 20 | The best way to reach out to Imgur for API support would be our |
21 | | -[Google Group](https://groups.google.com/forum/#!forum/imgur), [Twitter](https://twitter.com/imgurapi), or via |
| 21 | +[Google Group](https//groups.google.com/forum/#!forum/imgur), [Twitter](https//twitter.com/imgurapi), or via |
22 | 22 | api@imgur.com. |
23 | 23 |
|
24 | 24 | Installation |
25 | 25 | ------------ |
26 | 26 |
|
27 | 27 | pip install imgurpython |
28 | 28 |
|
| 29 | +Library Usage |
| 30 | +------------ |
| 31 | + |
| 32 | +Using imgurpython in your application takes just a couple quick steps. |
| 33 | + |
| 34 | +To use the client from a strictly anonymous context (no actions on behalf of a user) |
| 35 | + |
| 36 | +```python |
| 37 | + |
| 38 | +from imgurpython import ImgurClient |
| 39 | + |
| 40 | +client_id = 'YOUR CLIENT ID' |
| 41 | +client_secret = 'YOUR CLIENT SECRET' |
| 42 | + |
| 43 | +client = ImgurClient(client_id, client_secret) |
| 44 | + |
| 45 | +# Example request |
| 46 | +items = client.gallery() |
| 47 | +for item in items |
| 48 | + print item.link |
| 49 | + |
| 50 | +``` |
| 51 | + |
| 52 | +To initialize a client that takes actions on behalf of a user |
| 53 | + |
| 54 | +```python |
| 55 | +from imgurpython import ImgurClient |
| 56 | + |
| 57 | +client_id = 'YOUR CLIENT ID' |
| 58 | +client_secret = 'YOUR CLIENT SECRET' |
| 59 | + |
| 60 | +client = ImgurClient(client_id, client_secret) |
| 61 | + |
| 62 | +# Authorization flow, pin example (see docs for other auth types) |
| 63 | +authorization_url = client.get_auth_url('pin') |
| 64 | + |
| 65 | +# ... redirect user to `authorization_url`, obtain pin (or code or token) ... |
| 66 | + |
| 67 | +credentials = client.authorize('PIN OBTAINED FROM AUTHORIZATION', 'pin') |
| 68 | +client.set_user_auth(credentials['access_token'], credentials['refresh_token']) |
| 69 | +``` |
| 70 | + |
| 71 | +or if you already have an access/refresh token pair you can simply do |
| 72 | + |
| 73 | +```python |
| 74 | +from imgurpython import ImgurClient |
| 75 | + |
| 76 | +# If you already have an access/refresh pair in hand |
| 77 | +client_id = 'YOUR CLIENT ID' |
| 78 | +client_SECRET = 'YOUR CLIENT SECRET' |
| 79 | +access_token = 'USER ACCESS TOKEN' |
| 80 | +refresh_token = 'USER REFRESH TOKEN' |
| 81 | + |
| 82 | +# Note since access tokens expire after an hour, only the refresh token is required (library handles autorefresh) |
| 83 | +client = ImgurClient(client_id, client_secret, access_token, refresh_token) |
| 84 | +``` |
| 85 | + |
| 86 | +### Error Handling |
| 87 | +Error types |
| 88 | +* ImgurClientError - General error handler, access message and status code via |
| 89 | + |
| 90 | +```python |
| 91 | +try |
| 92 | + ... |
| 93 | +except ImgurClientError as e |
| 94 | + print e.error_message |
| 95 | + print e.status_code |
| 96 | +``` |
| 97 | + |
| 98 | +* ImgurClientRateLimitError - Rate limit error |
| 99 | + |
| 100 | +## ImgurClient Functions |
| 101 | + |
| 102 | +### Account |
| 103 | + |
| 104 | +* `get_account(username)` |
| 105 | +* `get_gallery_favorites(username)` |
| 106 | +* `get_account_favorites(username)` |
| 107 | +* `get_account_submissions(username, page=0)` |
| 108 | +* `get_account_settings(username)` |
| 109 | +* `change_account_settings(username, fields)` |
| 110 | +* `get_email_verification_status(username)` |
| 111 | +* `send_verification_email(username)` |
| 112 | +* `get_account_albums(username, page=0)` |
| 113 | +* `get_account_album_ids(username, page=0)` |
| 114 | +* `get_account_album_count(username)` |
| 115 | +* `get_account_comments(username, sort='newest', page=0)` |
| 116 | +* `get_account_comment_ids(username, sort='newest', page=0)` |
| 117 | +* `get_account_comment_count(username)` |
| 118 | +* `get_account_images(username, page=0)` |
| 119 | +* `get_account_image_ids(username, page=0)` |
| 120 | +* `get_account_album_count(username)` |
| 121 | + |
| 122 | +### Album |
| 123 | +* `get_album(album_id)` |
| 124 | +* `get_album_images(album_id)` |
| 125 | +* `create_album(fields)` |
| 126 | +* `update_album(album_id, fields)` |
| 127 | +* `album_delete(album_id)` |
| 128 | +* `album_favorite(album_id)` |
| 129 | +* `album_set_images(album_id, ids)` |
| 130 | +* `album_add_images(album_id, ids)` |
| 131 | +* `album_remove_images(album_id, ids)` |
| 132 | + |
| 133 | +### Comment |
| 134 | +* `get_comment(comment_id)` |
| 135 | +* `delete_comment(comment_id)` |
| 136 | +* `create_album(fields)` |
| 137 | +* `get_comment_replies(comment_id)` |
| 138 | +* `post_comment_reply(comment_id, image_id, comment)` |
| 139 | +* `comment_vote(comment_id, vote='up')` |
| 140 | +* `comment_report(comment_id)` |
| 141 | + |
| 142 | +### Custom Gallery |
| 143 | + |
| 144 | +* `get_custom_gallery(gallery_id, sort='viral', window='week', page=0)` |
| 145 | +* `get_user_galleries()` |
| 146 | +* `create_custom_gallery(name, tags=None)` |
| 147 | +* `custom_gallery_update(gallery_id, name)` |
| 148 | +* `custom_gallery_add_tags(gallery_id, tags)` |
| 149 | +* `custom_gallery_remove_tags(gallery_id, tags)` |
| 150 | +* `custom_gallery_delete(gallery_id)` |
| 151 | +* `filtered_out_tags()` |
| 152 | +* `block_tag(tag)` |
| 153 | +* `unblock_tag(tag)` |
| 154 | + |
| 155 | +### Gallery |
| 156 | + |
| 157 | +* `gallery(section='hot', sort='viral', page=0, window='day', show_viral=True)` |
| 158 | +* `memes_subgallery(sort='viral', page=0, window='week')` |
| 159 | +* `memes_subgallery_image(item_id)` |
| 160 | +* `subreddit_gallery(subreddit, sort='time', window='week', page=0)` |
| 161 | +* `subreddit_image(subreddit, image_id)` |
| 162 | +* `gallery_tag(tag, sort='viral', page=0, window='week')` |
| 163 | +* `gallery_tag_image(tag, item_id)` |
| 164 | +* `gallery_item_tags(item_id)` |
| 165 | +* `gallery_tag_vote(item_id, tag, vote)` |
| 166 | +* `gallery_search(q, advanced=None, sort='time', window='all', page=0)` |
| 167 | +* `gallery_random(page=0)` |
| 168 | +* `share_on_imgur(item_id, title, terms=1)` |
| 169 | +* `remove_from_gallery(item_id)` |
| 170 | +* `gallery_item(item_id)` |
| 171 | +* `report_gallery_item(item_id)` |
| 172 | +* `gallery_item_vote(item_id, vote='up')` |
| 173 | +* `gallery_item_comments(item_id, sort='best')` |
| 174 | +* `gallery_comment(item_id, comment)` |
| 175 | +* `gallery_comment_ids(item_id)` |
| 176 | +* `gallery_comment_count(item_id)` |
| 177 | + |
| 178 | +### Image |
| 179 | + |
| 180 | +* `get_image(image_id)` |
| 181 | +* `upload_from_path(path, config=None, anon=True)` |
| 182 | +* `upload_from_url(url, config=None, anon=True)` |
| 183 | +* `delete_image(image_id)` |
| 184 | +* `favorite_image(image_id)` |
| 185 | + |
| 186 | +### Conversation |
| 187 | + |
| 188 | +* `conversation_list()` |
| 189 | +* `get_conversation(conversation_id, page=1, offset=0)` |
| 190 | +* `create_message(recipient, body)` |
| 191 | +* `delete_conversation(conversation_id)` |
| 192 | +* `report_sender(username)` |
| 193 | +* `block_sender(username)` |
| 194 | + |
| 195 | +### Notification |
| 196 | + |
| 197 | +* `get_notifications(new=True)` |
| 198 | +* `get_notification(notification_id)` |
| 199 | +* `mark_notifications_as_read(notification_ids)` |
| 200 | + |
| 201 | +### Memegen |
| 202 | + |
| 203 | +* `default_memes()` |
| 204 | + |
| 205 | +Command Line Demo (deprecated) |
| 206 | +------------ |
| 207 | + |
29 | 208 | Configuration |
30 | 209 | ------------- |
31 | | - |
| 210 | +` |
32 | 211 | Configuration is done through the **config.json** (placed in `imgur-python/data`) file in JSON format. The contents of the file should be a JSON |
33 | | -object with the following properties: |
| 212 | +object with the following properties |
34 | 213 |
|
35 | 214 | ### client_id |
36 | 215 |
|
37 | | -**Key**: 'client_id' |
| 216 | +**Key** 'client_id' |
38 | 217 |
|
39 | | -**Type**: string [16 characters] |
| 218 | +**Type** string [16 characters] |
40 | 219 |
|
41 | | -**Description**: The Client-ID you got when you registered. Required for any API call. |
| 220 | +**Description** The Client-ID you got when you registered. Required for any API call. |
42 | 221 |
|
43 | 222 | ### secret |
44 | 223 |
|
45 | | -**Key**: 'secret' |
| 224 | +**Key** 'secret' |
46 | 225 |
|
47 | | -**Type**: string [40 characters] |
| 226 | +**Type** string [40 characters] |
48 | 227 |
|
49 | | -**Description**: The client secret you got when you registered, needed fo OAuth2 authentication. |
| 228 | +**Description** The client secret you got when you registered, needed fo OAuth2 authentication. |
50 | 229 |
|
51 | 230 | ### token_store |
52 | 231 |
|
53 | | -**Key**: 'token_store' |
| 232 | +**Key** 'token_store' |
54 | 233 |
|
55 | | -**Type**: object |
| 234 | +**Type** object |
56 | 235 |
|
57 | | -**Description**: Future configuration to control where the tokens are stored for persistent **insecure** storage of refresh tokens. |
| 236 | +**Description** Future configuration to control where the tokens are stored for persistent **insecure** storage of refresh tokens. |
58 | 237 |
|
59 | 238 | Command Line Usage |
60 | 239 | ------------------ |
61 | 240 |
|
62 | | -> Usage: python main.py (action) [options...] |
| 241 | +> Usage python main.py (action) [options...] |
63 | 242 | > |
64 | 243 | > ### OAuth Actions |
65 | | -> |
66 | | -> **credits** |
| 244 | +> |
| 245 | +> **credits** |
67 | 246 | > View the rate limit information for this client |
68 | 247 | > |
69 | | -> **authorize** |
| 248 | +> **authorize** |
70 | 249 | > Start the authorization process |
71 | 250 | > |
72 | | -> **authorize [pin]** |
| 251 | +> **authorize [pin]** |
73 | 252 | > Get an access token after starting authorization |
74 | 253 | > |
75 | | -> **refresh [refresh-token]** |
| 254 | +> **refresh [refresh-token]** |
76 | 255 | > Return a new OAuth access token after it's expired |
77 | 256 | > |
78 | 257 | > ### Unauthorized Actions |
79 | | -> |
80 | | -> **upload [file]** |
| 258 | +> |
| 259 | +> **upload [file]** |
81 | 260 | > Anonymously upload a file |
82 | 261 | > |
83 | | -> **list-comments [hash]** |
| 262 | +> **list-comments [hash]** |
84 | 263 | > Get the comments (raw JSON) for a gallery post |
85 | 264 | > |
86 | | -> **get-album [id]** |
| 265 | +> **get-album [id]** |
87 | 266 | > Get information (raw JSON) about an album |
88 | 267 | > |
89 | | -> **get-comment [id]** |
| 268 | +> **get-comment [id]** |
90 | 269 | > Get a particular comment (raw JSON) for a gallery comment |
91 | 270 | > |
92 | | -> **get-gallery [hash]** |
| 271 | +> **get-gallery [hash]** |
93 | 272 | > Get information (raw JSON) about a gallery post |
94 | | -> |
| 273 | +> |
95 | 274 | > ### Authorized Actions |
96 | | -> |
| 275 | +> |
97 | 276 | > **upload-auth [access-token] [file]** |
98 | 277 | > Upload a file to your account |
99 | 278 | > |
100 | 279 | > **comment [access-token] [hash] [text]** |
101 | 280 | > Comment on a gallery post |
102 | 281 | > |
103 | | -> **vote-gallery [token] [hash] [direction]** |
| 282 | +> **vote-gallery [token] [hash] [direction]** |
104 | 283 | > Vote on a gallery post. Direction can be either 'up', 'down', or 'veto' |
105 | 284 | > |
106 | | -> **vote-comment [token] [id] [direction]** |
107 | | -> Vote on a gallery comment. Direction can be either 'up', 'down', or 'veto' |
| 285 | +> **vote-comment [token] [id] [direction]** |
| 286 | +> Vote on a gallery comment. Direction can be either 'up', 'down', or 'veto' |
0 commit comments