Search code examples
flutterinstagramflutter-dependencies

How to solve HTML was returned instead of JSON in flutter


I want to fetch Instagram profile detail but I got error "HTML was returned instead of JSON".

I am using instagram_public_api: ^0.2.3 When I click on button then this error happened "HTML was returned instead of JSON" How can I fix the error?

RoundedLoadingButton(
              child: Text(
                'profile detail',
                style: TextStyle(color: Colors.white),
              ),
              controller: insta,
              onPressed: instaLoading
                  ? null
                  : () async {
                setState(() {
                  instaLoading = true;
                });
                FlutterInsta insta = FlutterInsta();
                //Get Profile Details(must be public)
                InstaProfileData user = await insta.getProfileData(instacontroller.text.toString());
                print(user.username);
                print(user.profilePicURL);
                print(user.bio);
                setState(() {
                  _isAddToContactLoading = true;
                });
                contact.success();
              },
            ),


Solution

  • If you look at the source code of instagram_public_api, you can see it sends a request to this url: "https://www.instagram.com/$username/?__a=1" and it expects JSON data instead of HTML.

    The thing is that URL is not returning JSON anymore. Instagram must have changed something on their side. but if you append another query param which is "&__d=dis" you may have chance to get JSON data. (You should still watch for rate limit though)

    My suggestion is instead of using "instagram_public_api", try using "flutter_insta" package. That one is more up to date.