0

我需要可靠地从此字符串中获取访问令牌:

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

我已经对其进行了解码,Uri.decodeComponent(authString)但是我不确定如何从 URL 片段中获取身份验证令牌。

谢谢

4

1 回答 1

3

您可以将其替换#?after 解码并将查询参数解析为普通 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'];
于 2020-06-05T01:49:53.310 回答