gpt4 book ai didi

flutter : Not getting code while Instagram login (Instagram login not working)

转载 作者:IT王子 更新时间:2023-10-29 07:22:22 31 4
gpt4 key购买 nike

我正在使用 flutter,我想在我的应用程序中实现使用 Instagram 登录。所以我关注这个tutorial用于 Instagram 登录,

我成功登录但未获取用户详细信息,它正在打开重定向 URI ( https://www.google.com/ ) 但未获取代码和访问 token 。

有知道的请帮帮我

Note: I am using flutter_webview_plugin for load webview in flutter.

这是为 Instagram 登录 打开 webview 的代码 ->

我的日志 print("Code ========== Code"); 不再打印了

  Future<Token> getToken(String appId, String appSecret) async {

Stream<String> onCode = await _server();
print("_server ========== _server");
String url =
"https://api.instagram.com/oauth/authorize?client_id=$appId&redirect_uri=https://www.google.com/&response_type=code";
final flutterWebviewPlugin = new FlutterWebviewPlugin();
flutterWebviewPlugin.launch(url);
final String code = await onCode.first;
print("Code ========== Code");
print("Code -> "+code);
final http.Response response = await http.post(
"https://api.instagram.com/oauth/access_token",
body: {"client_id": appId, "redirect_uri": "https://www.google.com/", "client_secret": appSecret,
"code": code, "grant_type": "authorization_code"});

flutterWebviewPlugin.close();


return new Token.fromMap(json.decode(response.body));
}

Future<Stream<String>> _server() async {
final StreamController<String> onCode = new StreamController();
HttpServer server =
await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8585);
server.listen((HttpRequest request) async {
final String code = request.uri.queryParameters["code"];
request.response
..statusCode = 200
..headers.set("Content-Type", ContentType.HTML.mimeType)
..write("<html><h1>You can now close this window</h1></html>");
await request.response.close();
await server.close(force: true);
onCode.add(code);
await onCode.close();
});
return onCode.stream;
}

最佳答案

iOS 配置如果有人看,将下面的代码添加到 Info.plist

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost:8585</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>

关于 flutter : Not getting code while Instagram login (Instagram login not working),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55063019/

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