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

6 次查看(过去 30 天)
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?

采纳的回答

Mohammad Sami
Mohammad Sami 2022-4-7
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 个评论
Hank Helmers
Hank Helmers 2022-4-8
Oh ok, that's what I was afraid of but wasn't sure. Thank you! Appreciate the help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by