Skip to content
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

[BUG] New unhandled link format #2089

Open
Aaeeschylus opened this issue Dec 10, 2024 · 3 comments
Open

[BUG] New unhandled link format #2089

Aaeeschylus opened this issue Dec 10, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Aaeeschylus
Copy link

Describe the bug
Instagram appears to be trialing or slowly implementing a new style of share URL for posts. This URL currently is not handled correctly by media_pk_from_url() as it returns the incorrect mediapk for the post. I would assume this is broken for anything else that uses direct URLs. This new URL only appears to be from some people via the app on Android so far (at least from what I have tested. Any post I "share -> copy link" gives the same style of url.

instagram\.com\/share\/p\/[a-zA-Z0-9!$*\-_]+ is the pattern I have been using to catch these new links and ignore them for now.

An example of this:
When I share the following post: https://www.instagram.com/p/DC2konOtSse/
I currently get this link: https://www.instagram.com/share/p/BALv9Ep4YH

When putting the original url into media_pk_from_url(), we get the mediapk of 3510154080158034718. Putting this into media_info() then gives us the expected result.
When putting the new url into media_pk_from_url(), we get the mediapk of 18066072412849671. Putting this into media_info() then fails.

To Reproduce
Hope instagram have rolled out the link to your device. Then "share post -> copy link" and you will get the new URL format

Traceback
Instagrapi doesn't actually error out when using media_pk_from_url() with the new link formats, however it returns incorrect mediapk values which when put into media_info(), cause the following:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/public.py", line 185, in _send_public_request
    response.raise_for_status()
  File "/home/pi/.local/lib/python3.10/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://www.instagram.com/graphql/query/?variables=%7B%22shortcode%22%3A%22BALv9Ep4YH%22%2C%22child_comment_count%22%3A3%2C%22fetch_comment_count%22%3A40%2C%22parent_comment_count%22%3A24%2C%22has_threaded_comments%22%3Afalse%7D&query_hash=477b65a610463740ccdb83135b2014db

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/media.py", line 259, in media_info
    media = self.media_info_gql(media_pk)
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/media.py", line 204, in media_info_gql
    data = self.public_graphql_request(
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/public.py", line 259, in public_graphql_request
    body_json = self.public_request(
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/public.py", line 122, in public_request
    raise e
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/public.py", line 99, in public_request
    return self._send_public_request(url, **kwargs)
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/public.py", line 208, in _send_public_request
    raise ClientUnauthorizedError(e, response=e.response)
instagrapi.exceptions.ClientUnauthorizedError: 401 Client Error: Unauthorized for url: https://www.instagram.com/graphql/query/?variables=%7B%22shortcode%22%3A%22BALv9Ep4YH%22%2C%22child_comment_count%22%3A3%2C%22fetch_comment_count%22%3A40%2C%22parent_comment_count%22%3A24%2C%22has_threaded_comments%22%3Afalse%7D&query_hash=477b65a610463740ccdb83135b2014db

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 359, in _send_private_request
    response.raise_for_status()
  File "/home/pi/.local/lib/python3.10/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://i.instagram.com/api/v1/media/18066072412849671/info/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/media.py", line 230, in media_info_v1
    result = self.private_request(f"media/{media_pk}/info/")
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 541, in private_request
    raise e
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 526, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 432, in _send_private_request
    raise MediaUnavailable(e, response=e.response, **last_json)
instagrapi.exceptions.MediaUnavailable: Media not found or unavailable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Discord/Bot/Cogs/insta.py", line 688, in on_message
    media_info = self.cl.media_info(media_pk)
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/media.py", line 269, in media_info
    media = self.media_info_v1(media_pk)
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/media.py", line 235, in media_info_v1
    raise MediaNotFound(e, media_pk=media_pk, **self.last_json)
instagrapi.exceptions.MediaNotFound: Media not found or unavailable

Expected behavior
I expect media_pk_from_url() to return the correct mediapk with the new URL format.

Desktop (please complete the following information):

  • OS: Raspbian GNU/Linux 10 (buster)
  • Python version 3.10.2
  • instagrapi version 2.1.3
@Aaeeschylus Aaeeschylus added the bug Something isn't working label Dec 10, 2024
@atakanakin
Copy link

Same issue, is there any update on this?

@atakanakin
Copy link

@Aaeeschylus Just wanted to share a simple workaround for handling the new format of links for reels.

Check out https://gist.github.com/atakanakin/132072f227e22e11a610f2fc4e86016e

@Aaeeschylus
Copy link
Author

@Aaeeschylus Just wanted to share a simple workaround for handling the new format of links for reels.

Check out https://gist.github.com/atakanakin/132072f227e22e11a610f2fc4e86016e

for handling reel links (instagram.com/reel/{id}), all I do is just replace reel with p and it works. Sadly that doesnt work with the share url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants