getTokenAndUserID method

Future<Map<String, dynamic>> getTokenAndUserID({
  1. required String appid,
  2. required String redirectUrl,
  3. required String code,
  4. required String appSecret,
})

Implementation

Future<Map<String, dynamic>> getTokenAndUserID({
  required String appid,
  required String redirectUrl,
  required String code,
  required String appSecret,
}) async {
  try {
    var url = Uri.parse('https://api.instagram.com/oauth/access_token');
    final body = {
      'client_id': appid,
      'redirect_uri': redirectUrl,
      'client_secret': appSecret,
      'code': code,
      'grant_type': 'authorization_code'
    };
    final response = await http.post(url, body: body);
    debugPrint('response: ${response.body}');
    return jsonDecode(response.body);
  } catch (e) {
    debugPrint('Error: $e');
    throw Exception(e);
  }
}