我需要获取一个Instagram用户ID#,以在Google Script中使用。

huangapple 未分类评论49阅读模式
英文:

I need to get an Instagram User ID# for use in Google Script

问题

我想将一个用户名插入到以下格式中:

https://www.instagram.com/{username}/?__a=1

感谢这个帖子给出的提示。

然后我需要在Java中访问该链接,这样做会呈现以下页面代码,为了节省空间,我已将其缩减。我以职业滑板手Nyjah Huston为例。

{"logging_page_id":"profilePage_8223552","show_suggested_profiles":false,"show_follow_dialog":false,"graphql":{"user":{"biography":"Sender\ud83d\ude08\n@nikesb @monsterenergy @elementbrand  @blackplaguebrewing @socialcbd @priverevaux","blocked_by_viewer":false,"restricted_by_viewer":null,"country_block":false,"external_url":"https://www.nike.com/t/sb-nyjah-free-skate-shoe-oKwn7N/AA4272-300","external_url_linkshimmed":"https://l.instagram.com/?u=https%3A%2F%2Fwww.nike.com%2Ft%2Fsb-nyjah-free-skate-shoe-oKwn7N%2FAA4272-300&e=ATMW9Q8NwN2Mcwm_Bd5I8DeuAKP4L7IHpy_PdylDnGU8qqokJU6Z1kh_emEIVfJ1q8Xtq1b0&s=1","edge_followed_by":{"count":3969537},"followed_by_viewer":false,"edge_follow":{"count":694},"follows_viewer":false,"full_name":"Nyjah Huston"

如您所见,用户ID是页面上的第一件事:

{"logging_page_id":"profilePage_8223552"

在此情况下,用户ID为8223552。我对Java相当新手,我需要知道如何访问该链接并解析数据,以便将用户ID转换为变量,供我在我的Google脚本中使用。感谢您的帮助!

英文:

I'd like to take a username and plug it into this format

https://www.instagram.com/{username}/?__a=1

thanks to this thread for that tip

I then need to follow that link in java, and when doing so it presents the following page code, which I've abridged to save space. I used professional Skateboarder Nyjah Huston as my example.

{"logging_page_id":"profilePage_8223552","show_suggested_profiles":false,"show_follow_dialog":false,"graphql":{"user":{"biography":"Sender\ud83d\ude08\n@nikesb @monsterenergy @elementbrand  @blackplaguebrewing @socialcbd @priverevaux","blocked_by_viewer":false,"restricted_by_viewer":null,"country_block":false,"external_url":"https://www.nike.com/t/sb-nyjah-free-skate-shoe-oKwn7N/AA4272-300","external_url_linkshimmed":"https://l.instagram.com/?u=https%3A%2F%2Fwww.nike.com%2Ft%2Fsb-nyjah-free-skate-shoe-oKwn7N%2FAA4272-300&e=ATMW9Q8NwN2Mcwm_Bd5I8DeuAKP4L7IHpy_PdylDnGU8qqokJU6Z1kh_emEIVfJ1q8Xtq1b0&s=1","edge_followed_by":{"count":3969537},"followed_by_viewer":false,"edge_follow":{"count":694},"follows_viewer":false,"full_name":"Nyjah Huston"

As you can see, the User ID is one of the first things on the page

{"logging_page_id":"profilePage_8223552"

the user id being 8223552 in this case. I'm quite new to java, and I need to know how to follow that link and parse that data in order to turn the user id into a var for use in my google script. Thank you for your help!

答案1

得分: 0

你可以轻松地解析这个JSON内容,得到一个仅包含你所需信息的对象:

class UserInformation{
    private String logging_page_id;
}

我建议这个选项,因为如果将来需要获取其他信息,你可以很容易地扩展这个对象。

关于如何进行转换,请参考这个stackoverflow链接

英文:

You can easily parse this JSON content to a object that has only the information you need:

class UserInformation{
    private String logging_page_id;
}

I suggest this option because if you need in the future to get another info, you can easily just extend the object.

How to do the conversion, please reference to this stackoverflow

huangapple
  • 本文由 发表于 2020年4月6日 09:44:23
  • 转载请务必保留本文链接:https://java.coder-hub.com/61051808.html
匿名

发表评论

匿名网友

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

确定