我正在使用Flutter,我想在应用程序中使用Instagram登录。因此,我正在关注Instagram登录的本教程,
我将成功登录,但没有获取用户详细信息,它是打开重定向uri (https://www.google.com/),并且没有获取代码和访问令。<<<<<<<<<<<<<<<<<<<<<<<<<<<<
如果您不知道,请帮助我。
注意:我正在使用 flutter_webview_plugin 用于加载WebView 扑来。
这是打开 Instagram登录的WebView的代码 ->
我的日志 print(" 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>
最后,我发现答案实际上是正确的,
我的错误是更改重定向uri
所以我有更改重定向uri https://www.google.com/to http://localhost:8585 and Instagram login works。
Use http://localhost:8585 this Redirect URI for Instagram login