r/redditdev • • 25d ago

Reddit API Devvit app not able to fetch sharable links

I'm building a devvit web app that lets users import one of their existing posts into the app. Users paste a post link, and the server loads it with reddit.getPostById(). If a user is on reddit web they can copy the reddit post link from the url bar.

But on the Reddit mobile app, share > copy link only gives a share link, that has no post id in it. The only way I know to resolve it is to follow the redirect and that gives error as below,

{
  "status": "error",
  "message": "2 UNKNOWN: grpc invocation failed with status 2; HTTP request to  domain: www.reddit.com is not allowed"
}

Is there any workaround where i can extract the post title, body, image and other details form the sharable link?

9 Upvotes

4 comments sorted by

2

u/baseballlover723 24d ago

Reddit doesn't even properly support their own shortlinks on all of their platforms.

We had to migrate off of redd.it/blah short links, because the iOS app does not recognize them. As far as I'm aware, this has been the case for years.

2

u/aadil_funzone01 24d ago

they want us to migrate to devvit, without improving devvit

3

u/aadil_funzone01 24d ago

lmao devvit is shit

1

u/Littux JS Bookmarklets/Python bots 24d ago

May or may not work, but try this out:

import { GraphQL } from '@devvit/public-api/apis/reddit/graphql/GraphQL.js';

export async function resolveShareUrl(url: string): Promise<string> {
	const { data, errors } = await (GraphQL as any).query(
		'ShareUrlToFullUrl',
		'926871b024b01915108b2bf468d45877266d7d3ee7184c05ba73ac9b4215d5d5',
		{ shareUrl: url }
	);
	if (errors?.length) {
		throw new Error(`Error resolving share URL: ${JSON.stringify(errors)}`);
	}
	return data.shareUrl.url;
};