我有一个带有一些图像的文件夹(.png和.jpg)。我的目标是将它们全部上传到imgur.com并从每个链接或ID中获取。
我尝试安装软件包imguR
和imgur_upload
,但未能安装它们。
有快速的工作吗?
答案 0 :(得分:0)
你可以用knitr做到这一点。这将上传图片并返回您的网址:
setwd("yourWD")
install.packages(knitr)
install.packages("RCurl")
install.packages("XML")
knitr::imgur_upload("fish2.jpg", key = "Yourimguraccountkey")
答案 1 :(得分:0)
首先,如果您在默认浏览器中登录了imgur帐户,请注销。在R中,尝试
tkn <- imgur_login()
您的浏览器将尝试打开:
https://api.imgur.com/oauth2/authorize?response_type=code&client_id=1babd0decbb90f2&redirect_uri=http%3A%2F%2Flocalhost%3A1410%2F&state=yVKVeDejjB
并输入错误:
{"data":{"error":"redirect_uri_mismatch","request":"\/oauth2\/authorize","method":"GET"},"success":false,"status":400}
删除网址末尾,保留:
https://api.imgur.com/oauth2/authorize?response_type=code&client_id=1babd0decbb90f2
现在,您将拥有使用用户名和密码登录的屏幕,然后您将获得:
身份验证完成。请关闭此页面并返回R。
#upload images
listoffileIDs <- character()
mylistf <- list.files(pattern = ".jpg|.png")
lapply(seq_along(mylistf), function(i)
{
y <- upload_image(mylistf[[i]], token = tkn)
Sys.sleep(5)
listoffileIDs[[i]] <<- paste(unlist(account_images(token = tkn))[[1]])
y
})
data.frame(mylistf = mylistf, listoffileIDs = listoffileIDs)
#add images to new album
firstalbum <- create_album(listoffileIDs, title = "firstalbum",
privacy = "hidden" , token = tkn)
firstalbum$id # album id
# add images to extant album https://imgur.com/a/ALBUMID
# example: get ID of first album
firstalbum <- account_albums(token = tkn)[[1]]#
add_album_images(firstalbum, listoffileIDs, token = tkn)