【发布时间】:2017-03-01 11:19:48
【问题描述】:
这是一个后续问题:Accessing Spotify API for Multiple Artists in R
我的目标是从 Spotify 的 API 中提取多个艺术家,然后按艺术家及其属性检索所有歌曲。
这就是我们迄今为止对上一个问题所做的结果:
检索有关艺术家的信息(不是按歌曲):
artistName = 'ytcracker'
HeaderValue = paste0('Bearer ', mytoken)
URI = paste0('https://api.spotify.com/v1/search?query=', artistName,'&offset=0&limit=20&type=artist')
response2 = GET(url = URI, add_headers(Authorization = HeaderValue))
Artist = content(response2)
Artist
如果您从上面的代码中知道艺术家 ID,则为多个艺术家。
URI = paste0('https://api.spotify.com/v1/artists?ids=', Artist$artists$items[[2]]$id,",", '1Mxqyy3pSjf8kZZL4QVxS0')
response2 = GET(url = URI, add_headers(Authorization = HeaderValue))
Artists = content(response2)
如何提取多位艺术家的歌曲及其属性?
这是音频功能的链接:
https://developer.spotify.com/web-api/get-several-audio-features/
这是我的尝试:
artistID = '1Mxqyy3pSjf8kZZL4QVxS0'
HeaderValue = paste0('Bearer ', mytoken)
URI = paste0('https://api.spotify.com/v1/audio-features', artistID)
response2 = GET(url = URI, add_headers(Authorization = HeaderValue))
Artist = content(response2)
Artist
回复:
raw(0)
https://github.com/rweyant/spotifyr
这是一个很好的参考,但即使在打开“httr”库后我也无法设置我的凭据。
set_credentials(client_id=CLIENTID,client_secret=CLIENTSECRET)
错误:找不到函数“set_credentials”
任何帮助都很好,谢谢!
使用 API 凭据修改开头部分:
clientID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
response = POST(
'https://accounts.spotify.com/api/token',
accept_json(),
authenticate(clientID, secret),
body = list(grant_type = 'client_credentials'),
encode = 'form',
verbose()
)
mytoken = content(response)$access_token
【问题讨论】:
-
@Hack-R 如果您有任何想法,因为我知道您能够解决上一个问题。谢谢!
-
这可能意味着该库未正确安装和加载,我对此进行了测试,并且没有递归安装依赖项。在新的 R 会话中,这应该可以工作
install.packages(c('httr','jsonlite','RSelenium','RCurl','XML','stringr','stringi','plyr'),dep=TRUE); devtools::install_github('rweyant/spotifyr') -
这是我执行此操作时出现的错误:分配错误(“client_redirect_uri”,client_redirect_uri,envir = .GlobalEnv):缺少参数“client_redirect_uri”,没有默认值
标签: r api spotify httr libspotify