I want to return only an image or video if URL is shared on any social media site.but if it is requested by user from browser I want to return content page containing that image. i know about social media open graph meta tags but Reddit is not working with these tags. it only works if i share jpeg , GIF or MP4 URL. so is it possible that my URL can return only media without any other content on page if requested by another site.
Open Graph is a metadata format that specifies, among other things, how to preview content on another page. Reddit uses these to determine thumbnails.
It sounds like what you're actually trying to do is switch what content is returned based on the HTTP referer. The specifics on how you would do this will vary depending on your application, but in very high-level psuedocode it'd be something like:
def serve_image(request):
if hostname(request.headers['HTTP_REFERER']) == 'reddit.com':
return image
return full_html
Note also that the referer isn't very reliable, although it's probably reliable enough for your task.