如何解决在Flutter中返回HTML而不是JSON的问题

huangapple go评论73阅读模式
英文:

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?

              child: Text(
                'profile detail',
                style: TextStyle(color: Colors.white),
              ),
              controller: insta,
              onPressed: instaLoading
                  ? null
                  : () async {
                setState(() {
                  instaLoading = true;
                });
                FlutterInsta insta = FlutterInsta();
                //获取配置文件的详情(必须是公共的)
                InstaProfileData user = await insta.getProfileData(instacontroller.text.toString());
                print(user.username);
                print(user.profilePicURL);
                print(user.bio);
                setState(() {
                  _isAddToContactLoading = true;
                });
                contact.success();
              },
            ),```

<details>
<summary>英文:</summary>

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

I am using instagram_public_api: ^0.2.3
When I click on button then this error happened &quot;HTML was returned instead of JSON&quot;
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();
},
),


</details>


# 答案1
**得分**: 0

如果你查看instagram_public_api的源代码,你会看到它发送一个请求到这个URL:"https://www.instagram.com/$username/?__a=1",它期望的是JSON数据而不是HTML。

问题是这个URL不再返回JSON了。Instagram必须在他们的一侧进行了一些更改。但是如果你添加另一个查询参数,即"&__d=dis",你可能有机会获得JSON数据。(尽管你仍然需要注意速率限制)

我的建议是,不要使用"instagram_public_api",而是尝试使用"flutter_insta"包。那个更加更新。

<details>
<summary>英文:</summary>

If you look at the source code of instagram_public_api, you can see it sends a request to this url: &quot;https://www.instagram.com/$username/?__a=1&quot; 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 &quot;&amp;__d=dis&quot; you may have chance to get JSON data. (You should still watch for rate limit though)

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

</details>



huangapple
  • 本文由 发表于 2023年3月7日 10:56:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657645.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定