praw-dev / praw

PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

Home Page:http://praw.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for new reddit share link

Aaeeschylus opened this issue · comments

Describe the solution you'd like

Within the past couple of weeks, reddit seems to have made a new format for their share links.

Normally, when you click share -> copy link, you would get a link like the following:
https://www.reddit.com/r/space/comments/15llt1x/two_consecutive_solar_flares_send_potential/?ref=share&ref_source=link

However, on mobile, you now get links like the following:
https://reddit.com/r/space/s/skZgKbbMDq
The string after s/ changes every time you share the link, even if it is the same account on the same post.

When resolving this link, it takes you to the original share link except with a share_id= query on the end:
https://www.reddit.com/r/space/comments/15llt1x/two_consecutive_solar_flares_send_potential/?share_id=T-5Gge1AFaeZCVqp2sW_N

Support for using this new link would be helpful.

Describe alternatives you've considered

Currently, I have had to use requests to follow the new share link in order to get the original link from headers -> location in order to use praw/asyncpraw.

Additional context

No response

@Aaeeschylus Could you please share the workaround that you tried with requests ?

@Aaeeschylus Could you please share the workaround that you tried with requests ?

requests.get(link, allow_redirects=False).headers["Location"]

Do note, it isn't 100% reliable. Sometimes you need to follow it multiple times before you get the real reddit link.

@Aaeeschylus Could you please share the workaround that you tried with requests ?

requests.get(link, allow_redirects=False).headers["Location"]

Do note, it isn't 100% reliable. Sometimes you need to follow it multiple times before you get the real reddit link.

Thanks for sharing this! I tried to run it a couple of times(in loop) but unfortunately it returns the same url back with just www added to the mobile link.

Edit: Inspired by your idea I found the solution to get the correct url always. We must specify Host in request header.

link = 'https://reddit.com/r/space/s/skZgKbbMDq'
h = {'Host': 'www.reddit.com'}
share_url = requests.get(link, headers=h, allow_redirects=False).headers['Location']

@Aaeeschylus Could you please share the workaround that you tried with requests ?

requests.get(link, allow_redirects=False).headers["Location"]
Do note, it isn't 100% reliable. Sometimes you need to follow it multiple times before you get the real reddit link.

Thanks for sharing this! I tried to run it a couple of times(in loop) but unfortunately it returns the same url back with just www added to the mobile link.

Edit: Inspired by your idea I found the solution to get the correct url always. We must specify Host in request header.

link = 'https://reddit.com/r/space/s/skZgKbbMDq'
h = {'Host': 'www.reddit.com'}
share_url = requests.get(link, headers=h, allow_redirects=False).headers['Location']

Yeah I would normally either run it multiple times until I got the correct link or just add www to the url. I didnt know about the header part so I will definitely try that if it gives the correct URL every time

This issue is stale because it has been open for 30 days with no activity.

Remove the Stale label or comment or this will be closed in 30 days.

This issue is stale because it has been open for 30 days with no activity.

Remove the Stale label or comment or this will be closed in 30 days.

commented

Yes, reddit is still using these stupid new links.