1

I am trying to validate an Instagram username, that the user should enter. I want to find out whether an account with the username exists or if not. I have tried it this way:

 final request = await http.get('https://www.instagram.com/$username/');

 if (request.statusCode != 404) {
 ...
 }

I also looked at a similar question: Check if instagram account name is available

The link that is mentioned in the answer:(https://www.instagram.com/username/?__a=1) works fine in the browser

(If the username exists, it shows all the information of the account, if it doesn't it shows two brackets that are empty)

but in my code I don't get statusCode 404 I get statusCode 200. I also can't catch an error. It is the same with the link from my code (https://www.instagram.com/$username/), I get statusCode 200. Is there a different way that I have not yet considered?

Thanks for your answers in advance!

Mo711
  • 533
  • 1
  • 6
  • 21

1 Answers1

2

It's just a http request, if you are getting a success status so check the body in the request, for example if you get a success code but the body is empty {} you can decode the body response and check it in this way:

  void checkUser() async {
    final request = await http.get('https://www.instagram.com/fakeUserExample/?__a=1');

    final decodeData = json.decode(request.body);

    if(decodeData.isEmpty){
      print(".:: User Not Found ::.");
    }
  }

Don't forget to import the import 'dart:convert';

Hope it helps.

Luis Miguel Mantilla
  • 1,664
  • 1
  • 9
  • 13