在 Dart 中解析 URI 片段
Parse URI Fragment in Dart
我需要从这个字符串可靠地获取访问令牌:
final authString = "myApp:%23access_token=abcd1234asdf1qwerty&scope=channel_feed_read&token_type=bearer"
我已经解码了它 Uri.decodeComponent(authString)
但我不确定如何从 URL 片段中获取授权令牌。
谢谢
您可以在解码后将 #
替换为 ?
,并将查询参数解析为普通 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'];
我需要从这个字符串可靠地获取访问令牌:
final authString = "myApp:%23access_token=abcd1234asdf1qwerty&scope=channel_feed_read&token_type=bearer"
我已经解码了它 Uri.decodeComponent(authString)
但我不确定如何从 URL 片段中获取授权令牌。
谢谢
您可以在解码后将 #
替换为 ?
,并将查询参数解析为普通 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'];