フィルターのクリア

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

11 ビュー (過去 30 日間)
Hank Helmers
Hank Helmers 2022 年 4 月 6 日
コメント済み: Royi Avital 2023 年 1 月 15 日
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!
Royi Avital
Royi Avital 2023 年 1 月 15 日
@Mohammad Sami, what if finaluri is a ZIP file. How can it be saved?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by