javascript 尝试在PowerShell中使用curl获取spotify API示例

bzzcjhmw  于 2023-06-28  发布在  Java
关注(0)|答案(1)|浏览(127)

在运行上述代码(从Spotify API获取艺术家)后,我一直在我的幻灯片中得到这个错误:

curl --request GET \ --url https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTy \ --header 'Authorization: Bearer XXX'

At line:2 char:5
+   --url 'https://api.spotify.com/v1/search?q=Lilbaby&type=artist' \
+     ~
Missing expression after unary operator '--'.
At line:2 char:5
+   --url 'https://api.spotify.com/v1/search?q=Lilbaby&type=artist' \
+     ~~~
Unexpected token 'url' in expression or statement.
At line:3 char:5
+   --header 'Authorization: Bearer BQCr8A...QoBCa4'
+     ~
Missing expression after unary operator '--'.
At line:3 char:5
+   --header 'Authorization: Bearer BQCr8A...QoBCa4'
+     ~~~~~~
Unexpected token 'header' in expression or statement.
+ CategoryInfo          : ParserError: (:) [], 
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator

我已经试了很多次,但仍然是同样的结果

s1ag04yj

s1ag04yj1#

在PowerShell中

专辑
$headers = @{
    Authorization="Bearer ####### your access token ######"
    Content='application/json'
}

Invoke-RestMethod -Method Get -Uri "https://api.spotify.com/v1/albums/4aawyAB9vmqN3uQ7FjRGTy" -Headers $headers

结果

艺术家
$response = Invoke-RestMethod -Method Get -Uri "https://api.spotify.com/v1/search?q=Lilbaby&type=artist" -Headers $headers
$releases | get-member 
$releases.artists

结果

参考资料

1 curl in PowerShell

2 Powershell Invoke-RestMethod Authorization Header

3 Wrangling REST APIs with PowerShell JSON Examples

相关问题