Here I am fetching user data from twitter API and this is the below code to get data from twitter API.
String findUserByIdurl =
"https://api.twitter.com/2/users?ids=${cookieValue}&user.fields=profile_image_url";
Map<String, String>? header = {
'Access-Control-Allow-Origin': '*',
"Access-Control-Allow-Credentials": "true",
"Authorization": "Bearer $bearerToken"
};
var findUserByIduri = Uri.parse(findUserByIdurl);
http.Response findUserByIdRes = await http.get(
findUserByIduri,
headers: header,
);
Here I have set all the required headers also but still getting this type of error:
Access to XMLHttpRequest at 'https://api.twitter.com/2/users?ids=1385217534681440259&user.fields=profile_image_url' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Any suggestions on how to solve this issue?