英文:
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 "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();
},
),
</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: "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.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论