Title: | 'Imgur.com' API Client Package |
---|---|
Description: | A complete API client for the image hosting service 'Imgur.com', including the an 'imgur' graphics device, enabling the easy upload and sharing of plots. |
Authors: | Thomas J. Leeper [aut, cre] , Aaron Statham [ctb], Yihui Xie [ctb] |
Maintainer: | Thomas J. Leeper <[email protected]> |
License: | GPL-3 |
Version: | 1.0.4 |
Built: | 2024-11-01 02:52:41 UTC |
Source: | https://github.com/cloudyr/imgur |
This package enables intuitive uploading of plots created in R to the free image hosting service [Imgur](http://www.imgur.com) simply, quickly, and intuitively via the [Imgur v3 API](http://api.imgur.com). The package is a complete client library for the Imgur API, meaning that one can also delete, favorite, and comment on images, as well as organize them in albums and galleries. By default, all images are loaded to Imgur anonymously. Optionally, using an OAuth2.0 login, users can also gain fully access to their own Imgur user account.
Thomas J. Leeper and Aaron Statham
Maintainer: Thomas J. Leeper <[email protected]>
Retrieve details of a user's account
account(account = 'me', ...) account_verified(...) send_verification(...)
account(account = 'me', ...) account_verified(...) send_verification(...)
account |
A username, by default the current user (if |
... |
Other arguments passed to HTTP request functions, for example: |
account
returns basic details of a user account. account_verified
indicates whether one's user account has been email-verified. send_verification
sends a verification email to the user's email account.
An object of class “imgur_account”.
Thomas J. Leeper
## Not run: # get account details for a user account account('thosjleeper') # check account verification tkn <- imgur_login() if(!account_verified(token = tkn)) send_verification(token = tkn) account(token = tkn) ## End(Not run)
## Not run: # get account details for a user account account('thosjleeper') # check account verification tkn <- imgur_login() if(!account_verified(token = tkn)) send_verification(token = tkn) account(token = tkn) ## End(Not run)
Retrieve details of a user's albums
account_albums(account = 'me', ids = TRUE, ...) account_album_count(account = 'me', ...)
account_albums(account = 'me', ids = TRUE, ...) account_album_count(account = 'me', ...)
account |
A username, by default the current user (if |
ids |
A logical indicating whether to only return album IDs. |
... |
Other arguments passed to HTTP request functions, for example: |
account_albums
retrieves details of a user's albums. By default (and if a token
argument is supplied), the current user's albums are returned. Specifying another username is also possible with or without a token
. account_album_count
returns just the number of albums, which is useful for handling pagination of the results.
For account_albums
, a list of objects of class “imgur_albums”. For account_album_count
, a number.
Thomas J. Leeper
## Not run: account_albums('thosjleeper') ## End(Not run)
## Not run: account_albums('thosjleeper') ## End(Not run)
Retrieve details of a user's albums
account_comments(account = 'me', ids = FALSE, ...) account_comment_count(account = 'me', ...)
account_comments(account = 'me', ids = FALSE, ...) account_comment_count(account = 'me', ...)
account |
A username, by default the current user (if |
ids |
A logical indicating whether to only return album IDs. |
... |
Other arguments passed to HTTP request functions, for example: |
account_comments
retrieves details of a user's comments. By default (and if a token
argument is supplied), the current user's comments are returned. Specifying another username is also possible with or without a token
. account_comment_count
returns just the number of comments, which is useful for handling pagination of the results.
For account_comments
, an object of class “imgur_comment”. For account_comment_count
, a number.
Thomas J. Leeper
## Not run: account_comments('thosjleeper') ## End(Not run)
## Not run: account_comments('thosjleeper') ## End(Not run)
Retrieve details of a user's favorite images
account_favorites(account = 'me', gallery = FALSE, ...)
account_favorites(account = 'me', gallery = FALSE, ...)
account |
A username, by default the current user (if |
gallery |
A logical indicating whether to only return gallery favorites. |
... |
Other arguments passed to HTTP request functions, for example: |
account_favorites
retrieves details of a user's favoriates. By default (and if a token
argument is supplied), the current user's favorites are returned. Specifying another username is also possible with or without a token
.
For account_favorites
, an object of class “imgur_gallery_image” or “imgur_gallery_album”.
Thomas J. Leeper
## Not run: account_favorites('thosjleeper') ## End(Not run)
## Not run: account_favorites('thosjleeper') ## End(Not run)
Retrieve details of a user's gallery profile
account_gallery(account = 'me', ...)
account_gallery(account = 'me', ...)
account |
A username, by default the current user (if |
... |
Other arguments passed to HTTP request functions, for example: |
account_gallery
returns basic details of a user's gallery profile, including counts of comments, likes, submissions, and trophies.
An object of class “imgur_gallery_profile”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() account_gallery(token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() account_gallery(token = tkn) ## End(Not run)
Retrieve details of a user's images
account_images(account = 'me', page = NULL, ids = TRUE, ...) account_image_count(account = 'me', ...)
account_images(account = 'me', page = NULL, ids = TRUE, ...) account_image_count(account = 'me', ...)
account |
A username, by default the current user (if |
page |
Optionally, a page of results to return. |
ids |
A logical indicating whether to only return image IDs. |
... |
Other arguments passed to HTTP request functions, for example: |
account_images
retrieves details of a user's images. By default (and if a token
argument is supplied), the current user's images are returned. Specifying another username is also possible with or without a token
. account_image_count
returns just the number of images, which is useful for handling pagination of the results.
For account_images
, an object of class “imgur_image”. For account_image_count
, a number.
Thomas J. Leeper
## Not run: account_images('thosjleeper') ## End(Not run)
## Not run: account_images('thosjleeper') ## End(Not run)
Retrieve and modify account settings
account_settings(bio = NULL, public_images = NULL, messaging_enabled = NULL, album_privacy = NULL, accepted_gallery_terms = NULL, ...)
account_settings(bio = NULL, public_images = NULL, messaging_enabled = NULL, album_privacy = NULL, accepted_gallery_terms = NULL, ...)
bio |
The biography of user, which is displayed in the gallery profile page. |
public_images |
A logical indicating whether images public by default. |
messaging_enabled |
A logical indicating whether private messages are allowed. |
album_privacy |
The default privacy for albums. One of “public”, “hidden”, or “secret”. |
accepted_gallery_terms |
A logical indicating whether the user agrees to the Imgur gallery terms. |
... |
Other arguments passed to HTTP request functions, for example: |
If none of the named arguments (other than token
) are specified, this retrieves settings of the account. If any of the named arguments are specified, those parameters are modified.
If not modifying settings, an object of “imgur_account_settings”, otherwise an object of “imgur_basic”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() # retrieve settings account_settings(token = tkn) # set albums to default to public account_settings(album_privacy = 'public', token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() # retrieve settings account_settings(token = tkn) # set albums to default to public account_settings(album_privacy = 'public', token = tkn) ## End(Not run)
Add images to or remove images from an album
add_album_images(album, id, ...) remove_album_images(album, id, ...) set_album_images(album, id, ...)
add_album_images(album, id, ...) remove_album_images(album, id, ...) set_album_images(album, id, ...)
album |
An album ID or object of class “imgur_album”. |
id |
A vector of one or more image IDs to add to the album or a list of objects of class “imgur_image”. |
... |
Other arguments passed to HTTP request functions, for example: |
add_album_images
adds the specified images to the album.
set_album_images
removes all current images from the album and adds the specified images to the album.
remove_album_images
removes the specified images from the album.
An object of class “imgur_basic”.
Thomas J. Leeper
Add images to the gallery
add_gallery_images(album = NULL, id = NULL, title = NULL, ...)
add_gallery_images(album = NULL, id = NULL, title = NULL, ...)
album |
An album ID or object of class “imgur_album” to add to the gallery. |
id |
An image ID or an object of class “imgur_image” to add to the gallery. |
title |
A title for the image |
... |
Other arguments passed to HTTP request functions, for example: |
This function adds the specified image or album to the gallery. title
is required by the API. If NULL
, the title is drawn from a call to get_album
or get_image
.
An object of class “imgur_gallery_image” or “imgur_gallery_album”.
Thomas J. Leeper
Description of Imgur API authentication options
All calls to the Imgur.com API must be authenticated. imguR provides two authentication methods: anonymous API key authentication (the default) and OAuth2.0 authentication.
By default, all calls are made anonymously. Most operations can be performed in this way. The package provides an API key for performing operations in this way. This default key can be overridden by passing key
argument through any function. This may be useful if you intend to make a large number of anonymous requests using your own registered application.
Alternatively, calls can be made with a user-specific OAuth2.0 token. This token is generated using imgur_login
in an interactive session. The token allows calls to be made to a specific Imgur.com user account, which eases making subsequent changes to uploaded images (e.g., updating their metadata, adding images to an album, or deleting images). The token can then be passed using the token
argument to any function.
Note: if both key
and token
arguments are supplied to a function, the token
argument always takes precedence.
## Not run: # OAuth2.0-authenticated use # interactive OAuth login tkn <- imgur_login() # upload a simple graph i <- imgur(token = tkn) hist(rnorm(100)) u <- imgur_off(i) # pass the `imgur_image` object to `update_image`: update_image(u, title = 'My graph', description = 'A simple graph', token = tkn) # or, pass just the image id: update_image(u$id, title = 'My graph', description = 'A simple graph', token = tkn) # periodically refresh token tkn$refresh() ## End(Not run) ## Not run: # anonymous use # upload a simple graph i <- imgur() hist(rnorm(100)) u <- imgur_off(i) # pass just the image deletehash: update_image(u$deletehash, title = 'My graph', description = 'A simple graph') ## End(Not run)
## Not run: # OAuth2.0-authenticated use # interactive OAuth login tkn <- imgur_login() # upload a simple graph i <- imgur(token = tkn) hist(rnorm(100)) u <- imgur_off(i) # pass the `imgur_image` object to `update_image`: update_image(u, title = 'My graph', description = 'A simple graph', token = tkn) # or, pass just the image id: update_image(u$id, title = 'My graph', description = 'A simple graph', token = tkn) # periodically refresh token tkn$refresh() ## End(Not run) ## Not run: # anonymous use # upload a simple graph i <- imgur() hist(rnorm(100)) u <- imgur_off(i) # pass just the image deletehash: update_image(u$deletehash, title = 'My graph', description = 'A simple graph') ## End(Not run)
Block a user from sending messages
block_sender(username, ...)
block_sender(username, ...)
username |
A character string containing an Imgur username. |
... |
Other arguments passed to HTTP request functions, for example: |
Block an Imgur user from sending messages.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() block_sender("thosjleeper", token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() block_sender("thosjleeper", token = tkn) ## End(Not run)
Create an album
create_album(id = NULL, title = NULL, description = NULL, privacy = NULL, layout = NULL, cover_id = NULL, ...)
create_album(id = NULL, title = NULL, description = NULL, privacy = NULL, layout = NULL, cover_id = NULL, ...)
id |
A vector of one or more image IDs to add to the album or a list of objects of class “imgur_image”. |
title |
Optionally, an album title. |
description |
Optionally, an album description. |
privacy |
The privacy for the album. One of “public”, “hidden”, or “secret”. |
layout |
The layout for the album. One of “blog”, “grid”, “horizontal”, or “vertical”.) |
cover_id |
An image ID or an object of class “imgur_image”. |
... |
Other arguments passed to HTTP request functions, for example: |
Creates an Imgur album with the specified images and metadata. All options are are optional. Images can only be added to anonymous albums with create_album
, not after the fact. Albums created with an OAuth2.0 authentication token can be modified in any way.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: i <- imgur() hist(rnorm(20)) img <- imgur_off(i) create_album(id = img, title = 'My first Imgur album', description = 'A simple album', privacy = 'hidden', layout = 'grid', cover_id = img) ## End(Not run)
## Not run: i <- imgur() hist(rnorm(20)) img <- imgur_off(i) create_album(id = img, title = 'My first Imgur album', description = 'A simple album', privacy = 'hidden', layout = 'grid', cover_id = img) ## End(Not run)
Create a comment on an image
create_comment(id, comment, parent = NULL, ...)
create_comment(id, comment, parent = NULL, ...)
id |
An image ID or an object of class “imgur_image”. |
comment |
A character string containing the comment. |
parent |
An optional comment ID to reply to. |
... |
Other arguments passed to HTTP request functions, for example: |
account_favorites
retrieves details of a user's favoriates. By default (and if a token
argument is supplied), the current user's favorites are returned. Specifying another username is also possible with or without a token
.
For account_favorites
, an object of class “imgur_gallery_image” or “imgur_gallery_album”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() # comment on an image cmt <- create_comment("vSXfU46", "This is a test comment", token = tkn) # create a reply comment create_comment("vSXfU46", "This is a test comment", parent = cmt, token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() # comment on an image cmt <- create_comment("vSXfU46", "This is a test comment", token = tkn) # create a reply comment create_comment("vSXfU46", "This is a test comment", parent = cmt, token = tkn) ## End(Not run)
Create a comment on an image
create_message(recipient, body, ...)
create_message(recipient, body, ...)
recipient |
A character string containing the recipient's Imgur username. |
body |
A character string containing the message. |
... |
Other arguments passed to HTTP request functions, for example: |
Send a message to another Imgur user.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() create_message("thosjleeper", "This is a test comment from imguR", token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() create_message("thosjleeper", "This is a test comment from imguR", token = tkn) ## End(Not run)
Delete an album
delete_album(album, ...)
delete_album(album, ...)
album |
An album ID or object of class “imgur_image”. If no |
... |
Other arguments passed to HTTP request functions, for example: |
Deletes an album.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: # using an OAuth token tkn <- imgur_login() a <- account_albums(token = tkn) delete_album(a[[1]], token = tkn) ## End(Not run)
## Not run: # using an OAuth token tkn <- imgur_login() a <- account_albums(token = tkn) delete_album(a[[1]], token = tkn) ## End(Not run)
Delete a comment from an image
delete_comment(comment, ...)
delete_comment(comment, ...)
comment |
A comment ID, perhaps returned by |
... |
Other arguments passed to HTTP request functions, for example: |
Delete a comment.
An object of class “imgur_basic”
Thomas J. Leeper
## Not run: tkn <- imgur_login() cmt <- create_comment("vSXfU46", comment = 'This is a test comment.') delete_comment(cmt, token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() cmt <- create_comment("vSXfU46", comment = 'This is a test comment.') delete_comment(cmt, token = tkn) ## End(Not run)
Delete a conversation
delete_conversation(id, ...)
delete_conversation(id, ...)
id |
A conversation ID, possibly returned by |
... |
Other arguments passed to HTTP request functions, for example: |
Deletes a conversation
An object of class “imgur_basic”.
Thomas J. Leeper
Delete an image
delete_image(id, ...)
delete_image(id, ...)
id |
An image ID or object of class “imgur_image”. If no |
... |
Other arguments passed to HTTP request functions, for example: |
Deletes an image.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: # using a deletehash, anonymously u <- upload_image('file.png') delete_image(u$deletehash) # using an OAuth token tkn <- imgur_login() u <- upload_image('file.png', token = tkn) delete_image(u, token = tkn) ## End(Not run)
## Not run: # using a deletehash, anonymously u <- upload_image('file.png') delete_image(u$deletehash) # using an OAuth token tkn <- imgur_login() u <- upload_image('file.png', token = tkn) delete_image(u, token = tkn) ## End(Not run)
Favorite an album
favorite_album(album, ...)
favorite_album(album, ...)
album |
An album ID or object of class “imgur_album”. |
... |
Other arguments passed to HTTP request functions, for example: |
Favorites an album.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() favorite_album("cVsXX", token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() favorite_album("cVsXX", token = tkn) ## End(Not run)
Favorite an image
favorite_image(id, ...)
favorite_image(id, ...)
id |
An image ID or object of class “imgur_image”. |
... |
Other arguments passed to HTTP request functions, for example: |
Favorites an image.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() favorite_image("DgqMUeq", token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() favorite_image("DgqMUeq", token = tkn) ## End(Not run)
Get album details and metadata, or images.
get_album(album, ...) get_album_images(album, ...)
get_album(album, ...) get_album_images(album, ...)
album |
An album ID or object of class “imgur_album”. |
... |
Other arguments passed to HTTP request functions, for example: |
Get album details and metadata, including images contained in the album.
An object of class “imgur_album”.
Thomas J. Leeper
## Not run: get_album("cVsXX") get_album_images("cVsXX") ## End(Not run)
## Not run: get_album("cVsXX") get_album_images("cVsXX") ## End(Not run)
Get a comment (and, optionally, its replies).
get_comment(comment, replies = FALSE, ...)
get_comment(comment, replies = FALSE, ...)
comment |
A comment ID, perhaps returned by |
replies |
A logical indicating whether to return replies to the comment, in addition to the comment itself. |
... |
Other arguments passed to HTTP request functions, for example: |
Retrivies a comment and, optionally, any replies to that comment.
An object of class “imgur_comment”
Thomas J. Leeper
Get a specific conversation or all conversations
get_conversations(id = NULL, ...)
get_conversations(id = NULL, ...)
id |
A conversation ID. If |
... |
Other arguments passed to HTTP request functions, for example: |
Retrieves a named conversation, possibly returned by get_conversations
, or all conversations.
An object of class “imgur_message”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() get_conversations(token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() get_conversations(token = tkn) ## End(Not run)
Get gallery details and metadata
get_gallery(section = 'hot', sort = 'viral', page = 0, window = 'day', showViral = TRUE, ...)
get_gallery(section = 'hot', sort = 'viral', page = 0, window = 'day', showViral = TRUE, ...)
section |
One of “hot” (the default), “top”, or “user”. |
sort |
One of “viral” (the default) or “time”. |
page |
A page number of results between 0 and 50. |
window |
If |
showViral |
If |
... |
Other arguments passed to HTTP request functions, for example: |
Get gallery image details and metadata.
An object of class “imgur_image”.
Thomas J. Leeper
## Not run: get_gallery() get_gallery('top', window = 'week') ## End(Not run)
## Not run: get_gallery() get_gallery('top', window = 'week') ## End(Not run)
Get album details and metadata for an album in the gallery.
get_gallery_album(album, ...)
get_gallery_album(album, ...)
album |
An album ID or object of class “imgur_album” or “imgur_gallery_album”. |
... |
Other arguments passed to HTTP request functions, for example: |
Get album details and metadata, for an album in the gallery. This is basically the same as “get_album”.
An object of class “imgur_gallery_album”.
Thomas J. Leeper
Get gallery image details and metadata
get_gallery_image(id, ...)
get_gallery_image(id, ...)
id |
An image ID or object of class “imgur_image” or “imgur_gallery_image”. |
... |
Other arguments passed to HTTP request functions, for example: |
Get gallery image details and metadata. This is basically the same as get_image
.
An object of class “imgur_image”.
Thomas J. Leeper
## Not run: s <- search_gallery(query = 'meme') get_gallery_image(s[[1]]) ## End(Not run)
## Not run: s <- search_gallery(query = 'meme') get_gallery_image(s[[1]]) ## End(Not run)
Get image details and metadata
get_image(id, ...)
get_image(id, ...)
id |
An image ID or object of class “imgur_image”. |
... |
Other arguments passed to HTTP request functions, for example: |
Get image details and metadata.
An object of class “imgur_image”.
Thomas J. Leeper
## Not run: get_image("vSXfU46") ## End(Not run)
## Not run: get_image("vSXfU46") ## End(Not run)
Get a specific notification or all notifications
get_notifications(id = NULL, only_new = FALSE, ...)
get_notifications(id = NULL, only_new = FALSE, ...)
id |
A conversation ID. If |
only_new |
A logical indicating whether only new notifications should be returned. Default is |
... |
Other arguments passed to HTTP request functions, for example: |
Retrieves a named notification, possibly returned by get_notifications
, or all (new) notifications.
An object of class “imgur_notification”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() get_notifications(only_new = TRUE, token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() get_notifications(only_new = TRUE, token = tkn) ## End(Not run)
Get random images from the public gallery
get_random_images(page = 0, ...)
get_random_images(page = 0, ...)
page |
A page number of results between 0 and 50. |
... |
Other arguments passed to HTTP request functions, for example: |
Get random images from the public gallery.
An object of class “imgur_gallery_album”.
Thomas J. Leeper
## Not run: get_random_images() ## End(Not run)
## Not run: get_random_images() ## End(Not run)
Get gallery details and metadata
get_reddit_gallery(subreddit, sort = 'time', page = 0, window = 'day', ...)
get_reddit_gallery(subreddit, sort = 'time', page = 0, window = 'day', ...)
subreddit |
A character string containing the name of a sub-reddit. |
sort |
One of “time” (the default) or “top”. |
page |
A page number of results between 0 and 50. |
window |
If |
... |
Other arguments passed to HTTP request functions, for example: |
Get gallery image details and metadata for a sub-reddit gallery.
An object of class “imgur_image”.
Thomas J. Leeper
## Not run: get_reddit_gallery('dataisbeautiful') ## End(Not run)
## Not run: get_reddit_gallery('dataisbeautiful') ## End(Not run)
Get sub-reddit gallery image details and metadata
get_reddit_image(subreddit, id, ...)
get_reddit_image(subreddit, id, ...)
subreddit |
A character string containing the name of a sub-reddit. |
id |
An image ID or object of class “imgur_image” or “imgur_gallery_image”. |
... |
Other arguments passed to HTTP request functions, for example: |
Get sub-reddit gallery image details and metadata. This is basically the same as get_gallery_image
or get_image
.
An object of class “imgur_gallery_image”.
Thomas J. Leeper
## Not run: g <- get_reddit_gallery('dataisbeautiful') get_reddit_image('dataisbeautiful', g[[1]]) get_image(g[[1]]) ## End(Not run)
## Not run: g <- get_reddit_gallery('dataisbeautiful') get_reddit_image('dataisbeautiful', g[[1]]) get_image(g[[1]]) ## End(Not run)
Get replies
get_replies(only_new = FALSE, ...)
get_replies(only_new = FALSE, ...)
only_new |
A logical indicating whether only new notifications should be returned. Default is |
... |
Other arguments passed to HTTP request functions, for example: |
Retrieves replies.
An object of class “imgur_notification”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() get_replies(only_new = TRUE, token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() get_replies(only_new = TRUE, token = tkn) ## End(Not run)
Basic workhorse HTTP method functions for executing Imgur.com API calls
imgurGET(endpoint, base_url = "https://api.imgur.com/3/", key = "1babd0decbb90f2", token = NULL, ...)
imgurGET(endpoint, base_url = "https://api.imgur.com/3/", key = "1babd0decbb90f2", token = NULL, ...)
endpoint |
A named API endpoint. |
base_url |
The base URL for the API (by default the v3 API URL). |
key |
An API key (by default, the imguR package API key). The API key for version of imguR < 1.0.0 was “4feb29d00face5bc1b9dae536e15c373”. Either |
token |
Optionally, an OAuth2.0 token (returned by |
... |
Other arguments passed to analogous HTTP method functions from httr. |
These are the basic workhorse functions for the package, which users should not need to access directly (except perhaps for debugging).
Generally, a list. For imgurDELETE
, an empty character string.
Thomas J. Leeper
Open a specified graphics device function an configure it to upload to Imgur and then close it using imgur_off
.
imgur(device = png, file = NULL, title = NULL, description = NULL, album = NULL, name = NULL, key = NULL, token = NULL, ...) imgur_off(obj, ...)
imgur(device = png, file = NULL, title = NULL, description = NULL, album = NULL, name = NULL, key = NULL, token = NULL, ...) imgur_off(obj, ...)
device |
A graphics device function. Default is |
file |
Name of the file to be uploaded to imgur.com |
title |
Optionally, an image title. |
description |
Optionally, an image description. |
album |
Optionally, an Imgur album ID. |
name |
Optionally, a file name, otherwise the |
key |
An API key. If |
token |
Optionally, an OAuth2.0 token (returned by |
obj |
An object of class “imgur_device”. |
... |
For |
imgur
is a wrapper for a local graphics device (by default, the png
function. A temporary file is created by the graphics device. After plotting, a call to imgur_off
uploads the file to imgur (using upload_image
) and a URL of the files location is returned.
For imgur
, an object of class “imgur_device” to be passed to imgur_off
. For imgur_off
, the response from upload_image
.
Thomas J. Leeper, based on code by Aaron Statham.
## Not run: i <- imgur('png') hist(rnorm(20)) imgur_off(i) ## End(Not run)
## Not run: i <- imgur('png') hist(rnorm(20)) imgur_off(i) ## End(Not run)
Complete an interactive login to Imgur to generate an OAuth2.0 token
imgur_login(client_id = "1babd0decbb90f2", secret = "06eed15f8e3662c20d7ff95a62853266400aae5a", cache = TRUE)
imgur_login(client_id = "1babd0decbb90f2", secret = "06eed15f8e3662c20d7ff95a62853266400aae5a", cache = TRUE)
client_id |
A graphics device function. Default is |
secret |
Name of the file to be uploaded to imgur.com |
cache |
A logical indicating whether to cache the OAuth2.0 token for use later on. If |
Most operations in the package can be performed anonymously using the default package API key. In order to perform most account-specific operations it is necessary to use OAuth authentication, which can only be performed interactively via a web browser. imgur_login
returns an OAuth2.0 reference class object that can be passed as the token
argument to all other functions in the package.
The OAuth token is moderately long lived; the response object contains a timestamp indicating its expiration time. The token can be subsequently refreshed using the refresh()
method.
If cache = TRUE
, the OAuth2.0 token is automatically cached in a file called “.httr-oauth” in the working directory. This token will then be loaded automatically the next time imgur_login
is called (even in a new R session). To override an existing cache, set cache = FALSE
.
An OAuth2.0 reference class object, returned by oauth2.0_token
.
Thomas J. Leeper
## Not run: # login interactively tkn <- imgur_login() # use token in the `imgur` device i <- imgur('png', token = tkn) hist(rnorm(20)) imgur_off(i) # reload previous token rm(tkn) # OAuth token is automatically stored by # `imgur_login` if `cache = TRUE` (the default) # It is reloaded by calling `imgur_login` tkn <- imgur_login() token$refresh() # refresh token ## End(Not run)
## Not run: # login interactively tkn <- imgur_login() # use token in the `imgur` device i <- imgur('png', token = tkn) hist(rnorm(20)) imgur_off(i) # reload previous token rm(tkn) # OAuth token is automatically stored by # `imgur_login` if `cache = TRUE` (the default) # It is reloaded by calling `imgur_login` tkn <- imgur_login() token$refresh() # refresh token ## End(Not run)
Mark a notification as read
mark_notification(id, ...)
mark_notification(id, ...)
id |
A notification ID. |
... |
Other arguments passed to HTTP request functions, for example: |
Marks a named notification as read so that it does not show in future get_notifications
results.
An object of class “imgur_basic”.
Thomas J. Leeper
View memes and meme templates
default_memes(...) get_memes_gallery(sort = 'viral', page = 0, window = NULL, ...) get_meme(id, ...)
default_memes(...) get_memes_gallery(sort = 'viral', page = 0, window = NULL, ...) get_meme(id, ...)
sort |
One of “viral” (the default), “time”, or “top”. |
page |
A page number of results between 0 and 50. |
window |
One of “day”, “week”, “month”, “year”, or “all”. |
id |
An image ID, perhaps returned by |
... |
Other arguments passed to HTTP request functions, for example: |
default_memes
returns a list of default memes available on Imgur. get_memes_gallery
returns a list of trending memes. get_meme
returns a specific meme image.
A list of objects of class “imgur_image” or “imgur_gallery_image”.
Thomas J. Leeper
## Not run: default_memes() get_memes_gallery('viral', page = 1) ## End(Not run)
## Not run: default_memes() get_memes_gallery('viral', page = 1) ## End(Not run)
Plot an “imgur_image” object
## S3 method for class 'imgur_image' plot(x, ...) ## S3 method for class 'imgur_gallery_image' plot(x, ...)
## S3 method for class 'imgur_image' plot(x, ...) ## S3 method for class 'imgur_gallery_image' plot(x, ...)
x |
An object of class “imgur_image” or “imgur_gallery_image”. |
... |
Other arguments passed to HTTP request functions, for example: |
Plot an object of class “imgur_image” or “imgur_gallery_image” in an R graphics window.
Invisibly, an object of class “imgur_image” or “imgur_gallery_image”.
Thomas J. Leeper
## Not run: plot(get_image("vSXfU46")) ## End(Not run)
## Not run: plot(get_image("vSXfU46")) ## End(Not run)
Check user- and package-level rate limits
rate_limit(...)
rate_limit(...)
... |
Other arguments passed to HTTP request functions, for example: |
This function returns a list detailing user- and package-level API rate limits. All calls to the API deduct one unit from rate limits, except for upload_image
, which deducts 10. Rate limits are lower for anonymous requests than for authenticated requests. Limits exist at the user level and at the package level. The user-level rate limit are automatically reset periodically. The response object documents when that limit will be reset.
Rate limits are automatically checked during each request. Options can be set for low remaining usage warnings. By default (when the package is loaded) those options are: options(imgur_user_rate_warning = 20)
and options(imgur_client_rate_warning = 100)
.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: # rate limit for anonymous requests rate_limit() # rate limit for authenticated requests tkn <- imgur_login() rate_limit(token = tkn) ## End(Not run)
## Not run: # rate limit for anonymous requests rate_limit() # rate limit for authenticated requests tkn <- imgur_login() rate_limit(token = tkn) ## End(Not run)
Remove images from the gallery
remove_gallery_image(id, ...)
remove_gallery_image(id, ...)
id |
An image ID or an object of class “imgur_image” to add to the gallery. |
... |
Other arguments passed to HTTP request functions, for example: |
This function removes the specified image from the gallery.
An object of class “imgur_basic”.
Thomas J. Leeper
Report a comment as inappropriate.
report_comment(comment, ...)
report_comment(comment, ...)
comment |
A comment ID, perhaps returned by |
... |
Other arguments passed to HTTP request functions, for example: |
Reports a comment as inappropriate.
An object of class “imgur_basic”.
Thomas J. Leeper
Report a gallery image as inappropriate.
report_gallery_image(id, ...)
report_gallery_image(id, ...)
id |
An image ID. |
... |
Other arguments passed to HTTP request functions, for example: |
Reports a gallery image as inappropriate.
An object of class “imgur_basic”.
Thomas J. Leeper
Report a user for inappropriate behavior
report_sender(username, ...)
report_sender(username, ...)
username |
A character string containing an Imgur username. |
... |
Other arguments passed to HTTP request functions, for example: |
Report an Imgur user for inappropiate behavior.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: tkn <- imgur_login() block_sender("someuser", token = tkn) ## End(Not run)
## Not run: tkn <- imgur_login() block_sender("someuser", token = tkn) ## End(Not run)
Search Imgur public gallery
search_gallery(query, sort = 'time', page = 1, ...)
search_gallery(query, sort = 'time', page = 1, ...)
query |
A character string containing a search term. |
sort |
One of “time” or “top”. |
page |
A page number. |
... |
Other arguments passed to HTTP request functions, for example: |
Search the gallery and return gallery images and associated metadata.
An object of class “imgur_gallery_album”.
Thomas J. Leeper
## Not run: search_gallery(query = 'meme') ## End(Not run)
## Not run: search_gallery(query = 'meme') ## End(Not run)
Update album metadata
update_album(album, id = NULL, title = NULL, description = NULL, privacy = NULL, layout = NULL, cover_id = NULL, ...)
update_album(album, id = NULL, title = NULL, description = NULL, privacy = NULL, layout = NULL, cover_id = NULL, ...)
album |
An album ID or object of class “imgur_album”. If no |
id |
A vector of one or more image IDs to add to the album or a list of objects of class “imgur_image”. |
title |
Optionally, an album title. |
description |
Optionally, an album description. |
privacy |
The privacy for the album. One of “public”, “hidden”, or “secret”. |
layout |
The layout for the album. One of “blog”, “grid”, “horizontal”, or “vertical”.) |
cover_id |
An image ID or an object of class “imgur_image”. |
... |
Other arguments passed to HTTP request functions, for example: |
Updates the images or metadata of an album. All options are are optional. To anonymously update an album, album
must be the deletehash value from create_album
.
An object of class “imgur_basic”.
Thomas J. Leeper
## Not run: # update using a deletehash, anonymously i <- imgur() hist(rnorm(20)) img <- imgur_off(i) a1 <- create_album(id = img, title = 'My first Imgur album', description = 'A simple album', privacy = 'hidden', layout = 'grid', cover_id = img) update_album(a1$deletehash, title = 'My second Imgur album') # update using an OAuth token tkn <- imgur_login() a2 <- create_album(id = img, title = 'My first Imgur album', description = 'A simple album', privacy = 'hidden', layout = 'grid', cover_id = img, token = tkn) update_album(a2, title = 'My second Imgur album') ## End(Not run)
## Not run: # update using a deletehash, anonymously i <- imgur() hist(rnorm(20)) img <- imgur_off(i) a1 <- create_album(id = img, title = 'My first Imgur album', description = 'A simple album', privacy = 'hidden', layout = 'grid', cover_id = img) update_album(a1$deletehash, title = 'My second Imgur album') # update using an OAuth token tkn <- imgur_login() a2 <- create_album(id = img, title = 'My first Imgur album', description = 'A simple album', privacy = 'hidden', layout = 'grid', cover_id = img, token = tkn) update_album(a2, title = 'My second Imgur album') ## End(Not run)
Update image metadata
update_image(id, title = NULL, description = NULL, ...)
update_image(id, title = NULL, description = NULL, ...)
id |
An image ID or object of class “imgur_image”. If no |
title |
Optionally, an image title. |
description |
Optionally, an image description. |
... |
Other arguments passed to HTTP request functions, for example: |
Update the title or description of an already-uploaded image.
A logical, with the class “imgur_basic”.
Thomas J. Leeper
## Not run: # using a deletehash, anonymously u <- upload_image('file.png') update_image(u$deletehash, title = 'New Title') # using an OAuth token tkn <- imgur_login() u <- upload_image('file.png', token = tkn) update_image(u, title = 'New Title', token = tkn) ## End(Not run)
## Not run: # using a deletehash, anonymously u <- upload_image('file.png') update_image(u$deletehash, title = 'New Title') # using an OAuth token tkn <- imgur_login() u <- upload_image('file.png', token = tkn) update_image(u, title = 'New Title', token = tkn) ## End(Not run)
Uploads a named image file to Imgur, optionally to a specified album.
upload_image(file, title = NULL, description = NULL, album = NULL, name = NULL, type = 'file', ...) imgur_upload(file, title = NULL, description = NULL, album = NULL, name = NULL, type = 'file', ...)
upload_image(file, title = NULL, description = NULL, album = NULL, name = NULL, type = 'file', ...) imgur_upload(file, title = NULL, description = NULL, album = NULL, name = NULL, type = 'file', ...)
file |
Name of the file to be uploaded to imgur.com |
title |
Optionally, an image title. |
description |
Optionally, an image description. |
album |
Optionally, an Imgur album ID. |
name |
Optionally, a file name, otherwise the |
type |
Should be “file”. |
... |
Other arguments passed to HTTP request functions, for example: |
upload_image
allows users to upload a named file to Imgur. imgur_upload
is an alias that can serve as a drop-in replacement for the imgur_upload
function in the knitr package.
A list parsed from the imguR JSON response after uploading the plot (see the imgur API for details).
Thomas J. Leeper, adapted from code by Aaron Statham (imguRupload
from imguR v0.1) and Yihue Xie (knitr::imgur_upload
).
https://api.imgur.com/endpoints/image#image-upload
## Not run: pdf(tmpfile <- tempfile()) hist(rnorm(20)) dev.off() upload_image(tmpfile) ## End(Not run)
## Not run: pdf(tmpfile <- tempfile()) hist(rnorm(20)) dev.off() upload_image(tmpfile) ## End(Not run)
Vote a comment up or down.
vote_comment(comment, vote = 'up', ...)
vote_comment(comment, vote = 'up', ...)
comment |
A comment ID, perhaps returned by |
vote |
A character string indicating the direction of the vote, one of “up” or “down”. |
... |
Other arguments passed to HTTP request functions, for example: |
Votes a comment up or down.
An object of class “imgur_basic”
Thomas J. Leeper