Apologies, the error I get is in the data = webread line and says the server returns "status 401" which is unauthorized, this is why I think my syntax regarding sending the authorization token is incorrect..
Issue getting data from morningstar API using token
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have been trying to pull data from a Morninstar API with the following code:
% Manually set Authorization header field in weboptions
options = weboptions('HeaderFields',{'Authorization',...
['Basic ' matlab.net.base64encode([Username ':' Password])];...
'Cache-Control', 'no-cache'; ...
'Content-Type', 'application/x-www-form-urlencoded';...
'grant_type=authorization_code&code=7962e5a1-dd81-412f-8993-6&redirect_uri=https%3A%2F%2abcd8027.morningstar.com%2Ftestapp%2Fcallback', ''});
% Make a request using these options
response = webwrite('https://www.us-api.morningstar.com/token/oauth', options)
access_token = response.access_token;
token_type = response.token_type;
headerFields = {'Authorization', ['Bearer: ', access_token]};
options2 = weboptions('HeaderFields', headerFields);
data = webread('https://www.us-api.morningstar.com/ec/v1/securities/FOUSA06N2B%7CFEUSA04ABV?universeIds=FOUSA%7CFEUSA%7CFCUSA&langCult=en-US&dataPoints=n%7Ct¤cyId=USD', options2);
I am trying to pull the data on the securities in the following example for starters just to prove out that I can get access to the server before I try getting the data I actually want:
I am successfully getting the token as the value of response above is what is expected if you look at the example here:
So I think my issue is the syntax I am using in setting up options2 to pass my token to the server with the data. I have tried multiple ways of forming the request using both HeaderFields and KeyName/KeyValue. I have also tried setting RequestMethod to 'GET' even though I shouldnt have to do that with webread.
I am sure I am missing something simple and obvious but for the life of me I cannot figure it out!
Réponses (0)
Voir également
Catégories
En savoir plus sur Web Services dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!