-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix anonymous fetch of users and posts #2533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi! I've just ran your changes, it works like a charm!! Thank you :) |
|
I tried your branch as well, and it works great. Though it seems that I still get the 401 unauthorized errors when it loads the session from file, so it asks me for the password every time. Not sure if it's related to the same core issue you sent the PR for, or if it's an unrelated issue. |
|
@kakaroto yeah I know, this PR doesn't aim to solve that problem yet... I'm not really using that functionality so I don't know if/when I'll fix it, sorry! |
No worries! I'll try to give it a poke at some point if I get the time. Thanks for your changes, it helps already! |
|
I forked the repository and pushed your commit and it seemed to work great, but after 96 posts downloaded, I got the same JSON Query to graphql/query: 401 Unauthorized - "fail" status, message "Please wait a few minutes before you try again." error. None of my JSON files are readable either, unsure if I did something wrong or if picking an account with a lot of posts had something to do with it. |
Unfortunately I can't say for certain but I am pretty sure I downloaded an account with over 96 posts last week just fine using these fixes. |
Nope, just ran an update on an account and it grabbed 4 missing posts just fine |
|
Works, thank you |
|
Newbie question here, I've been trying to use this PR but I don't think I really know how to, could you be so kind and provide the commands needed to download this corrected version? |
|
Hi @latinokodi, I don't know if there are better ways to do this but what I would do is cloning the repo from which I've created the modifications and then install it in your project Hope it can be helpful! |
|
Works, thank you |
How did you make it work? |
|
no longer works |
|
Now needs at least the login even for open profiles |
|
It stopped working. Damn Meta. |
It works!!! |
|
Thanks for the contribution — we’ll be happy to review it. Two observations upfront:
Looking forward to the updated version. |
|
Hey @aandergr, If there’s already an upcoming/v4.15 branch in the works, maybe we could merge these changes into it so it’s part of the next release? |
|
@aandergr sorry for replying so late! Thank you for your response.. I think I did what you said but I'm not 100% so feel free to tell me what you think |
|
The "new" iPhone struct actually looks like the old (non-iPhone) struct, created with the constructor. |
|
Hey, I tried your PR and I actually was able to download a profile for the first time in ages. The only thing I'm confused about is my terminal is littered with these error messages: Update: I tried another profile and now I'm suddenly not getting those errors. Weird |
|
Upon further usage, I've come to suspect that those errors are related to a change on Instagram's backend sometime around 2020. Older posts don't seem to yield those errors. Seeing that the main branch still doesn't work for anonymous fetching, would you also be able to take a look at fetching |
|
Hi. I had finally the chance to have a deeper look into this. Thanks for your patience and for sharing your work on this! The staticmethod Post::from_new_iphone_struct is actually not needed. The structure that is returned is not a "new iphone structure", it is rather the classical structure that the Post constructor parses. So replacing the Post.from_new_iphone_struct() invocations with Post() seems the way to go.
With these changes, downloading anonymously seems fixed for profiles. |
|
It needs to be checked whether this change also works logged-in and downloads the same quality as before. If not, some of the changes need to be encapsulated in a check whether we are logged-in or anonymously. |
instaloader/structures.py
Outdated
| @classmethod | ||
| def from_new_iphone_struct(cls, context: InstaloaderContext, media: Dict[str, Any]): | ||
| """Create a post from a given new_iphone_struct. | ||
| .. versionadded:: 4.15""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This classmethod is actually redundant; it seems the Post constructor can be invoked instead.
instaloader/structures.py
Outdated
| for node in media["carousel_media"]]} | ||
| return cls(context, fake_node, Profile.from_iphone_struct(context, media["user"]) if "user" in media else None) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change; please remove.
instaloader/structures.py
Outdated
| video_url=node['video_url'] if is_video else None) | ||
| video_url=str(node['video_url']) if is_video else "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This triggers a broken sidecar node video downloading for every non-video sidecar node.
instaloader/structures.py
Outdated
| metadata = self._context.get_iphone_json('api/v1/users/web_profile_info/', | ||
| params={'username': self.username}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change relevant?
.gitignore
Outdated
| venv/ | ||
| *.egg-info/ | ||
| build/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated; I suggest to add those to your local .git/info/exclude to not have them listed as untracked files. (also see https://git-scm.com/docs/gitignore )
|
Yes, I mentioned in my earlier comment that this branch can't download reels, but what I really meant was highlights - I had the terminology wrong. I find that using this branch for anonymous fetching of posts then logging in on the main branch to grab highlights is a good strategy, as it greatly reduces the amount of requests you're making on your account, lowering the chances of a ban. Of course, you don't get the full resolution content, but I think it's close enough. |
Also, fix mypy error regarding `video_url` in the `shortcode_to_mediaid` function
…ruct` for legacy reasons Also, add tests for shortcode retrieved posts
|
We did some major cleanup on this PR: We removed the Post.from_new_iphone_struct. It was only used in Instaloader.get_location_posts and Hashtag.get_top_posts, where it did not fix the download, neither anonymously nor logged-in, and in Hashtag.get_posts, which is deprecated. So the only significant change was in Profile.get_posts, which fixed the download for the anonymous case, but in return broke it for the logged-in case. We rewrote this change to affect the behavior only when not logged in. The change in the unit test did not test any of the other changes. |
|
Sorry for the late reply @aandergr, but thanks for the support and all those fixes :) |
Hello! This PR aims to fix the problem that caused many and many users to be unable to download anything, either profiles and posts.
This problem affected a lot of us, but in the end, there was simply some backend change made by Instagram, so it was needed to change some parameters and adapt to the new responses, and now some things like
_convert_iphone_carouselare not even needed anymore.Actually there are way more incompatible changes (i.e. logged in user doesn't work, neither the fetching of users by their id) so someone should take care also of that.
I think I made all the changes correctly, but a deeper look from a more experienced "instaloader developer" would be appreciated, thanks!
Fixes #2532, #2528, #2307, #2517, #2501, #2511, #2508