'How to make an API call with key secret in flutter using getconnect?
My app need to communicate with the server using REST API, my API contains key and secret. I need to establish the connection with server and fetch the data from server using GetX library with the help of GetConnect.
Here is the piece of code I'm using to communicate with the server, to fetch the data from server based on user-id but I'm not able to achieve it.
import 'package:get/get.dart';
import 'package:get/get_connect.dart';
class ApiService extends GetConnect {
final _baseUrl = 'https://api.instagram.com/'; // Dummy End Point
final _headersMap = {'SANBOX-API': 'VN0VQ2DW651L91Y25TVO'}; // Dummy REST API key and secret
// Fetch User Friends
Future<UserFriends?> fetchUserFriends({required String userId}) async {
String apiUrl = '${_baseUrl}user_firends?user_id=${userId}';
final response = await get(apiUrl, headers: _headersMap);
if (response.statusCode == HttpStatus.ok) {
return userFriendsFromJson(response.body);
} else {
return null;
}
}
}
When ever I execute this snippet code, I'm getting null
Guide me what I'm missing here.
Thanks in advance!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
