在Dart中解析URI片段

问题描述 投票:0回答:1

我需要从这个字符串中可靠地获取访问令牌。

final authString = "myApp:%23access_token=abcd1234asdf1qwerty&scope=channel_feed_read&token_type=bearer"

我已经把它解码了 Uri.decodeComponent(authString) 但我不知道如何从URL片段中获取Auth token。

谅谅

flutter dart oauth uri twitch-api
1个回答
1
投票

你可以把它换成 #? 解码后,将查询参数作为一个普通的Uri进行解析。

final link = 'myApp:%23access_token=abcd1234asdf1qwerty&scope=channel_feed_read&token_type=bearer';

final decoded = Uri.decodeFull(link).replaceAll('#', '?');
final uri = Uri.parse(decoded);

final access_token = uri.queryParameters['access_token'];
final token_type = uri.queryParameters['token_type']
final scope = uri.queryParameters['scope'];
© www.soinside.com 2019 - 2024. All rights reserved.