Is there a way to get the redirect url after a https / api request?

31 vues (au cours des 30 derniers jours)
Hank Helmers
Hank Helmers le 6 Avr 2022
Commenté : Royi Avital le 15 Jan 2023
I'm using the Spotify API and in order to get authorization I need to get the url of the redirected page after completing the first api request.
client_id = "CLIENT_CODE"; % Specific Application client id
redirect_uri = 'REDIRECT_URL';
scope = 'user-read-private user-read-email';
response_type = 'code';
% Authorization url
auth_url = "https://accounts.spotify.com/authorize?";
auth_url = strcat(auth_url, "client_id="+client_id);
auth_url = strcat(auth_url, "&redirect_uri="+redirect_uri);
auth_url = strcat(auth_url, "&response_type="+response_type);
web(auth_url)
Right now, when you input my actual client code and redirect_url, it opens up the authorization page and then after you authorize (or don't) the page is redirect to a url like this:
REDIRECT_URL/?code=AQDkK3AcQqCnoiV37f1Ied1DjOyEINjnzKB1HA-JO7c0HIyYL2VR0PGrbawMQiKkuquXUl7UlI19VaEvDp2jzxsOF_scEItkktas0voMUgc4p2q1W8i0Kx4a_i3KB0dB6AtRO_ruQWXCVto_9ZQLn_bqJ7soiGsYN_3rLO6nheky5_VREMdzi9IVlzQg0A
This information after the 'code=' is the authorization key that I need.
Does anyone know how to retrieve this in MATLAB?

Réponse acceptée

Mohammad Sami
Mohammad Sami le 7 Avr 2022
You can use the matlab.net.http interface to follow the redirects.
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI('https://goo.gl/maps/co8U2mMv8zFweDzN8');
[response,completedrequest,history] = send(request,uri);
finaluri = history(end).URI;
disp(finaluri);
URI with properties: Scheme: "https" UserInfo: [0×0 string] Host: "consent.google.com" Port: [] EncodedAuthority: "consent.google.com" Path: ["" "ml"] EncodedPath: "/ml" Query: [1×6 matlab.net.QueryParameter] EncodedQuery: "continue=https://www.google.com/maps/place/Houston,%2BTX,%2BUSA/@29.8174782,-95.6814846,10z/data%3D!3m1!4b1!4m5!3m4!1s0x8640b8b4488d8501:0xca0d02def365053b!8m2!3d29.7596088!4d-95.3723145&gl=IE&m=0&pc=m&hl=en&src=1" Fragment: [0×0 string] Absolute: 1 EncodedURI: "https://consent.google.com/ml?continue=https://www.google.com/maps/place/Houston,%2BTX,%2BUSA/@29.8174782,-95.6814846,10z/data%3D!3m1!4b1!4m5!3m4!1s0x8640b8b4488d8501:0xca0d02def365053b!8m2!3d29.7596088!4d-95.3723145&gl=IE&m=0&pc=m&hl=en&src=1"
  4 commentaires
Hank Helmers
Hank Helmers le 8 Avr 2022
Oh ok, that's what I was afraid of but wasn't sure. Thank you! Appreciate the help!
Royi Avital
Royi Avital le 15 Jan 2023
@Mohammad Sami, what if finaluri is a ZIP file. How can it be saved?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Call Web Services from MATLAB Using HTTP dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by