英文:
Handling query parameters in authorization callback on flutter
问题
I'm trying to use Spotify Web API with Flutter. I'm requesting for a user login from Spotify with openAuthorizationUrl() but it's returning a web page and I don't know how to handle it. I have to use this "code" parameter but I'm not even in the app. Here is the function:
void openAuthorizationUrl() async {
final clientId = 'cd3acd...7efbc';
final redirectUri = 'https://localhost:8888/callback';
final scope = 'user-read-private user-read-email user-top-read';
final response_type = 'code';
final authorizationUrl =
'https://accounts.spotify.com/authorize?response_type=$response_type&client_id=$clientId&scope=$scope&redirect_uri=$redirectUri';
if (await canLaunchUrl(Uri.parse(authorizationUrl))) {
var x = await launchUrl(Uri.parse(authorizationUrl));
} else {
throw 'Could not launch $authorizationUrl';
}
}
Here is the screenshot of the application:
英文:
I'm trying to use Spotify Web API with Flutter. I'm requesting for a user login from Spotify with openAuthorizationUrl() but it's returning a web page and I don't know how to handle it. I have to use this "code" parameter but I'm not even in the app. Here is the function:
void openAuthorizationUrl() async {
final clientId = 'cd3acd...7efbc';
final redirectUri = 'https://localhost:8888/callback';
final scope = 'user-read-private user-read-email user-top-read';
final response_type = 'code';
final authorizationUrl =
'https://accounts.spotify.com/authorize?response_type=$response_type&client_id=$clientId&scope=$scope&redirect_uri=$redirectUri';
if (await canLaunchUrl(Uri.parse(authorizationUrl))) {
var x = await launchUrl(Uri.parse(authorizationUrl));
} else {
throw 'Could not launch $authorizationUrl';
}
}
答案1
得分: 0
我将URL方案从http更改为我的应用程序名称,例如“com.example.myapp://localhost:8888/callback/”,并使用了flutter_web_auth2包。 http方案并不总是始终将重定向到应用程序,所以。
英文:
I changed url scheme http to my app's name like "com.example.myapp://localhost:8888/callback/" and I used flutter_web_auth2 package. http scheme is not redirecting to application all the time, so.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论