flutter - Flutter:登录 Instagram 时未获取代码(Instagram 登录不起作用)
问题描述
我正在使用颤振,我想在我的应用程序中使用 Instagram 登录。所以我正在按照本教程进行 Instagram 登录,
我登录成功但没有获取用户详细信息,它正在打开重定向 URI ( https://www.google.com/ ) 并且没有获取代码和访问令牌。
如果您知道任何事情,请帮助我。
注意:我正在使用flutter_webview_plugin在flutter 中加载webview。
这是为Instagram 登录打开 webview 的代码->
我的日志print("代码 ========== 代码"); 不再打印
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>
推荐阅读
- python - 我在烧瓶中遇到端口问题,如何更改端口?
- r - 将格式应用于 R 中的多个数组
- python-3.x - ArgumentError: hasproperty of NULL PyObject using PyPlot in julia 1.5.3 in JupyterNotebook
- r - 模型适合 Lavaan CFA。这段代码有什么问题?
- shell - 从最后一个字符开始的字符串 shell 脚本中的子字符串
- web - 网站未从 www 重定向到 https
- spring-security - 永远不会调用 Spring 安全过滤器
- opencv - OpenCV 文本检测
- django - Django url前缀关联
- android - 未解决的参考:requireLensFacing | 安卓工作室