problems with webread/weboptions
显示 更早的评论
im trying to make a request to spotify with spotify api BUT when im filling the weboptions parameters and then execute the webread this is the result:
error: weboptions: HeaderFields must be of size m-by-2
error: called from
set.HeaderFields at line 311 column 11
webread at line 89 column 24
my code is here:
options=weboptions('HeaderFields',{'Accept' 'application/json';'Content-Type' 'application/json';'Authorization' 'Bearer BQCS1-3qa1vbElaF9wa2hoZacWQfULK_aH5QJt5bqAAYQ0oBBPXxjtbTg5X--DkI8cNdwdQ5dyP5ohpTDYAPMIkBmytfptLBUvRl4ZM14BIhO0By2DxcQvurUcaGjHSgEjfBOLQO2W9ok5aw0HEjZQ-HZh1IFvLFSamM-gqVFIeYYRsXQXk'})
then i execute the webread:
response=webread("https://api.spotify.com/v1/me",options)
the auth-token is copied exactly from the spotify website where i created the token
4 个评论
Walter Roberson
2021-5-12
I formatted your code and un-split the line... and the result works on my system.
Alexandros Loukas
2021-5-12
Walter Roberson
2021-5-12

Walter Roberson
2021-5-12
The code you posted had
options=weboptions('HeaderFields',{'Accept' 'application/json';'Content-Type' 'application/json';'Authorization' 'Bearer BQCS1-3qa1vbElaF9wa2hoZacWQfULK_aH5QJt5bqAAYQ0oBBPXxjtbTg5X--
DkI8cNdwdQ5dyP5ohpTDYAPMIkBmytfptLBUvRl4ZM14BIhO0By2DxcQvurUcaGjHSgEjfBOLQO2W9ok5aw0HEjZQ-HZh1IFvLFSamM-gqVFIeYYRsXQXk'})
which was split across two lines and did not construct the strings properly. I removed the newline to join it together into one string
options=weboptions('HeaderFields',{'Accept' 'application/json';'Content-Type' 'application/json';'Authorization' 'Bearer BQCS1-3qa1vbElaF9wa2hoZacWQfULK_aH5QJt5bqAAYQ0oBBPXxjtbTg5X--DkI8cNdwdQ5dyP5ohpTDYAPMIkBmytfptLBUvRl4ZM14BIhO0By2DxcQvurUcaGjHSgEjfBOLQO2W9ok5aw0HEjZQ-HZh1IFvLFSamM-gqVFIeYYRsXQXk'})
under the assumption that the split was an artificat that did not exist in your actual code. The resulting line worked fine for me.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!