gpt4 book ai didi

flutter - 在Dart中解析URI片段

转载 作者:行者123 更新时间:2023-12-03 04:46:23 25 4
gpt4 key购买 nike

我需要从该字符串可靠地获取访问 token :
final authString = "myApp:%23access_token=abcd1234asdf1qwerty&scope=channel_feed_read&token_type=bearer"
我已经将其解码为Uri.decodeComponent(authString),但随后不确定如何从URL片段中获取身份验证 token 。

谢谢

最佳答案

您可以在解码后将#替换为?,并将查询参数解析为普通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'];

关于flutter - 在Dart中解析URI片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62206354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com