【发布时间】:2021-09-01 00:41:28
【问题描述】:
我正在尝试编写一个可以在 Github Actions 等无头环境中运行的 R 包。使用 httr,您可以使用以下代码在交互式会话中使用 Spotify API 进行身份验证(从 spotifyr 窃取)
get_spotify_authorization_code <- function(
client_id = Sys.getenv("SPOTIFY_CLIENT_ID"),
client_secret = Sys.getenv("SPOTIFY_CLIENT_SECRET"),
scope = get_scopes()
) {
endpoint <- oauth_endpoint(authorize = 'https://accounts.spotify.com/authorize',
access = 'https://accounts.spotify.com/api/token')
app <- oauth_app('spotty', client_id, client_secret)
token <- safely(.f=oauth2.0_token)(
endpoint = endpoint,
app = app,
scope = scope)
if (!is.null(token$error)) {
token$error
} else {
token$result
}
}
当你第一次运行它时,它会弹出一个浏览器窗口来进行身份验证。这只需要执行一次,然后从那时起使用刷新令牌。
有没有办法可以调整它,使其不使用web-application-flow 并使用其他类型的可以无头运行的身份验证。我知道有“客户端凭据流”,但它不允许访问用户资源,我希望能够访问保存的播放列表等内容(即meendpoint、'https://api.spotify.com/v1/me/tracks/')
【问题讨论】:
-
如果您想获取外部客户的数据,您需要向他们展示 auth popup 以清楚地说“我需要这个这个和这个”。使用客户端凭据流,您只能访问您的数据,因为您提供了您的应用凭据
-
@HüseyinBABAL 我只想访问我自己的数据
-
查看客户端凭据流程,here