【发布时间】:2018-12-31 23:31:14
【问题描述】:
我正在尝试在 Flutter 中制作一个使用 Spotify API 的应用。我特别需要使用 Spotify Web Api,因为它是唯一允许访问用户私人播放列表的。
我正在尝试为身份验证编写代码,但是当我发送 GET 请求时,我得到了 HTML 作为回报。
这是我正在使用的代码:
void _auth() async{
final String state = randomAlphaNumeric(20);
final Map<String, String> authQueryParameters = {
"client_id": SPOTIFY_CLIENT_ID,
"response_type": "code",
"redirect_uri": "painless_playlist://callback",
"state": state,
"scope": "playlist-read-private playlist-read-collaborative playlist-modify-private playlist-modify-public user-library-read"
};
Uri uri = new Uri.https(SPOTIFY_ACCOUNT_AUTHORITY, "authorize", authQueryParameters);
print(uri.toString());
HttpClientRequest request = await httpClient.getUrl(uri);
HttpClientResponse response = await request.close();
await response.transform(Utf8Decoder()).listen(print);
}
这就是返回的内容:
<!DOCTYPE html>
<html lang="en" dir="ltr" ng-app="accounts" ng-csp ng-strict-di>
<head>
<meta charset="utf-8">
<title ng-bind="('loginTitle' | localize) + ' - Spotify'">Spotify</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<base href="/">
<link rel="icon" href="https://accounts.scdn.co/images/favicon.ace4d8543bbb017893402a1e9d1ac1fa.ico">
<link href="https://accounts.scdn.co/css/index.2298e26e3e5796a7bb68.css" media="screen" rel="stylesheet">
<script async defer
src="https://www.google.com/recaptcha/api.js?render=explicit"
nonce="wLHnpa4sDVHdmLiYTMXAZw=="></script>
<script defer src="https://accounts.scdn.co/js/index.2298e26e3e5796a7bb68.js" sp-bootstrap></script>
<meta ng-non-bindable sp-bootstrap-data='{"country":"US","captchaSiteKey":null,"useCaptcha":false,"BON":["0","0",1206798229]}'>
</head>
<body ng-controller="LoginController">
<div ng-include="template"></div>
</body>
</htm
我不知道该怎么办。我应该弄清楚如何打开浏览器并显示这个 html 吗?我四处搜索,一些资源说要在浏览器中打开 uri 而不是发出 GET 请求,但这只会在 Spotify 的网站上显示一个错误页面。
我不知道该怎么做;任何帮助将不胜感激!
【问题讨论】:
-
我不知道如何完全解决您的问题,但您必须显示 HTML 以便用户可以使用他的 Spotify 帐户登录
标签: dart flutter httprequest spotify