ImgurAPI perl library
ImgurAPI::Client is a perl5 client library for interfacing with Imgur's API endpoints.
Installation
- Clone the repository
git clone https://github.com/selftaught/ImgurAPI.git - Cd into the repo root and generate a makefile:
perl Makefile.pl - Make it:
make && make test && make install
Usage
Instantiating the client
my $client = ImgurAPI::Client->new( \%optional );
Valid options are:
note that all are optional but the library will throw if its needed and not defined
client_idclient_secretaccess_keyrapidapi_key- commercial rapidapi / mashape api key (commercial use)
format_type- api endpoint response format type
- valid values are
json(default) andxml
oauth_cb_state- parameter appended to oauth2 authorization url returned from
oauth2_authorize_url()which may be useful to your application upon receipt of the response.
- parameter appended to oauth2 authorization url returned from
Authorization
If you haven't already, register an application for an OAuth2 client ID and secret here.
You will need to authorize your OAuth2 application if you haven't already done so. You can get the authorization URL with oauth2_authorize_url:
my $auth_url = $client->oauth2_authorize_url();
# return to user's browser for manual authorization
Once the application has been authorized, the access token, refresh token and expires_in values will be passed to the callback endpoint URL that was specified during application registration. The callback endpoint should collect the values and store them somewhere your client calling code on the backend can pull the access token from and then pass it to the client.
my $access_token = get_access_token_from_some_db();
$client->set_access_token($access_token);
The client library doesn't handle refreshing the access token for you automatically. It is left up to the calling code to refresh the access token when it expires. This is so you can keep the refresh token updated in the database you stored it in initially. The client library is unaware of the database so we leave it up to you to manage.
Requests
Imgur API endpoint subroutines
Account
account($username)- get information about an account$username- string - imgur account username
account_album($username, $album_id)- get information about an account album$username- string - imgur account username$album_id- int|string - album id
account_album_count($username)- get the count of account albums$username- string - imgur account username
account_album_delete($username, $album_id)- delete an account album$username- string - imgur account username$album_id- int|string - album id
account_album_ids($username, \%optional)- get a list of account album ids$username- string - imgur account username\%optional- hashref - hashref of optional parameterspage- int|str - page number
account_albums($username, \%optional)- list account albums$username- string - imgur account username\%optional- hashref - hashref of optional parameterspage- int|str - page number
account_block_create($username)- block a user$username- string - imgur account username to block
account_block_status($username)- determine if the user making the request has blocked a username$username- string - imgur account username to check if is blocked
account_blocks()- list all accounts being blocked by the requesting accountaccount_comment($username, $comment_id)- get information about a comment$username- string - imgur account username$comment_id- string - comment id
account_comment_count($username)$username- string - imgur account username
account_comment_delete($username, $comment_id)$username- string - imgur account username$comment_id- string - comment id
account_comment_ids($username, \%optional)$username- string - imgur account username\%optional- hashref - hashref of optional parameterspage- int|string - page numbersort- string - best, worst, oldest or newest (default)
account_comments($username, \%optional)$username- string - imgur account username\%optional- hashref - hashref of optional parameterspage- int|string - page numbersort- string - best, worst, oldest or newest (default)
account_delete($password, \%optional)$password- string - imgur account password\%optional- hashref - hashref of optional paramsreasons- arrayref of strings - reasons for deleting accountfeedback- string - feedback for imgur
account_favorites($username, \%optional)$username- string - imgur account username\%optional- hashref - hashref of optional paramspage- int|string - page number (default: 0)sort- string - oldest or newest (default)
account_tag_follow($tag_name)$tag_name- string - tag to follow
account_tag_unfollow($tag_name)$tag_name- string - tag to unfollow
account_gallery_favorites($username, \%optional)$username- string - imgur account username\%optional- hashref - hashref of optional paramspage- int|string - page number (default: 0)sort- string - oldest or newest (default)
account_image($username, $image_id)- get info about an image$username- string - imgur account username$image_id- string - image id to get information about
account_image_count($username)$username- string - imgur account username
account_image_delete($username, $image_id)- delete an image$username- string - imgur account username$image_id- string - image id to delete
account_image_ids($username, \%optional)$username- string - imgur account username\%optional- hashref - hashref of optional paramspage- int|string - page number (default: 0)
account_images($username, \%optional)$username- string - imgur account username\%optional- hashref - hashref of optional paramspage- int|string - page number (default: 0)
account_reply_notifications($username, new)$username- string - imgur account username\%optional- hashref - hashref of optional paramsnew- int|boolean - 1 for unviewed notification and 0 for viewed (default: 1)
account_settings($username)$username- string - imgur account username
account_settings_update($username, \%settings)$username- string - imgur account username\%settings- hashref - hashref of settings to updatebio- string - biography displayed on the accountpublic_images- int|boolean - set images to private or public by defaultmessaging_enabled- int|boolean - enable / disable private messagesaccepted_gallery_terms- int|boolean - user agreement to imgur gallery termsusername- string - valid username between 4 and 63 alphanumeric charactersshow_mature- int|boolean - toggle display of mature contentnewsletter_subscribed- int|boolean - toggle subscription to email newsletter
account_submissions($username, \%optional)$username- string - imgur account username\%optional- hashref - hashref of optional paramspage- int|string - page number (default: 0)
account_verify_email_send($username)$username- string - imgur account username
account_verify_email_status($username)$username- string - imgur account username
Album
album($album_id)$album_id- string
album_images($album_id)$album_id- string
album_create(\%options)\%optionsids- arrayrefdeletehashes- arrayreftitle- stringdescription- stringcover- string
album_update($album_id, \%options)$album_id- string\%optionsids- arrayrefdeletehashes- arrayreftitle- stringdescription- stringcover- string
album_delete($album_id)$album_id- string
album_favorite($album_id)$album_id- string
album_images_set($album_id, \@ids)$album_id- string\@ids- arrayref
album_images_add($album_id, \@ids)$album_id- string\@ids- arrayref
album_images_delete($album_id, \@ids)$album_id- string\@ids- arrayref
Comment
comment($comment_id)- get comment info$comment_id- string
comment_delete($comment_id)$comment_id- string
comment_replies($comment_id)$comment_id- string
comment_reply($comment_id, $image_id, $comment)$comment_id- string
comment_vote($comment_id, $vote)$comment_id- string$vote- string - can be 'up', 'down' or 'veto'
comment_report($comment_id)$comment_id- string
Gallery
gallery(\%optional)- optional:
section- hot (default), top, usersort- viral (default), top, time, risingpage- page numberwindow- day (default), week, month, year, allshow_viral- 0 or 1 (default)album_preview- 0 or 1 (default)
- optional:
gallery_album($album_id)gallery_image($image_id)gallery_image_remove($image_id)gallery_item($id)gallery_item_comment($id, $comment)gallery_item_comment_info($id, $comment_id)gallery_item_comments($id, \%optional)- optional:
sort- one of: best (default), top, or new
- optional:
gallery_item_report($id, \%optional)- optional:
reason- integer value reason for report. values:1- doesn't belong on imgur2- spam3- abusive4- mature content not marked as mature5- pornography
- optional:
gallery_item_tags_update($id, \@tags)gallery_item_vote($id, $vote)vote- up, down, or veto
gallery_item_votes($id)gallery_item_tags($id)gallery_search($query, \%optional, \%advanced)- optional:
sort- viral, top, time (default), risingpage- page number (default: 0)window- day, week, month, year, all (default)
- advanced (note: if advanced search parameters are set, query string is ignored):
q_all- search for all of these words (and)q_any- search for any of these words (or)q_exactly- search for exactly this word or phraseq_not- exclude results matching thisq_type- show results for file type (jpg, png, gif, anigif, album)q_size_pix- size ranges, small (500 pixels square or less) | med (500 to 2,000 pixels square) | big (2,000 to 5,000 pixels square) | lrg (5,000 to 10,000 pixels square) | huge (10,000 square pixels and above)
- optional:
gallery_share_image($id, $title, \%optional)- optional:
topic- topic nameterms- if the user has not accepted the terms yet, this endpoint will return an error. pass1to by-passmature- set to1if the post is maturetags- The name of the tags you wish to associate with a post. Can be passed as an array or csv string
- optional:
gallery_share_album($id, $title, \%optional)- optional:
topic- topic nameterms- if the user has not accepted the terms yet, this endpoint will return an error. pass1to by-passmature- set to1if the post is maturetags- The name of the tags you wish to associate with a post. Can be passed as an array or csv string
- optional:
gallery_subreddit($subreddit, \%optional)- optional:
sort- viral (default), top, time, risingpage- page number (default: 0)window- day, week (default), month, year, all
- optional:
gallery_subreddit_image($subreddit, $image_id)gallery_tag($tag, \%optional)- optional:
sort- viral (default), top, time, risingpage- page number (default: 0)window- day, week (default), month, year, all
- optional:
gallery_tag_info($tag)gallery_tags()
Image
image($image_id)image_upload($src, \%optional)srcimage or video source - can be one of type: file, url, base64 or raw stringtypeimage or video source type - can be one of: file, url, base64 or raw stringoptionaloptional data can includetitle- title of the contentdescription- description of the content
image_delete($image_id)image_favorite($image_id)image_update($image_id, \%optional)- optional:
title- content titledescription- content description
- optional:
Feed
feed()
Client member sub-routines
Getters
response()response_content()access_token()ratelimit_headers()- returns rate limit key value pairs from imgur api response:
userlimituserremaininguserresetclientlimitclientremaining
- returns rate limit key value pairs from imgur api response:
Setters
set_state(state)set_access_token(access_token)set_refresh_token(refresh_token)set_expiration_datetime(datetime)set_no_auth()