Giter VIP home page Giter VIP logo

Comments (1)

BukhariH avatar BukhariH commented on September 22, 2024

Thanks for identifying this problem but as always this is a problem with reddit's appalling api design. APIs should not redirect & clients most certainly should not follow them.

Problem

Well try searching this non-existent url:
http://reddit.com/search.json?q=http://www.youtube.com/watch?v=XAAgX54433aMCdfI2

You can see the response is:

"{}"

However, if you search this non-existent phrase:
http://reddit.com/search.json?q=fhhfhkjdfhkjfsfhjksdhjkdhjhj45784375437895hiudfhjkvkjkczjdasudouiryr35345783789rhsfhjkfsafioui73478923yudhgsSDFSJFHSJFHJKFJKHSSFKHJKJHSFKJHF24874872378dfkjdhajIUOQWUQWQE

The response is:

{"kind": "Listing", "data": {"modhash": "1rrvj60ghsw34387e669712d48255154140bd129cefbb3cf80", "children": [], "after": null, "before": null}}

This is stupid. This brakes RedditKit. This is reddit's api.

Solution
If you look at the source code:
https://github.com/reddit/reddit/blob/master/r2/r2/controllers/front.py#L871

You can see reddit detects whether something is a url then redirects the query to /submit?url={YOUR_URL}.

What we need to effectively do is detect whether something is a url then query:
reddit.com/submit.json?url={YOUR_URL}

This will return:

{"kind": "Listing", "data": {"modhash": "qqxkyfpfkzbb0b02851d1ed46d470b2500f50c42d7d46c879e", "children": [{"kind": "t3", "data": {"domain": "youtube.com", "banned_by": null, "media_embed": {"content": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2FXAAgXaMCdfI%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXAAgXaMCdfI&image=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=text%2Fhtml&schema=youtube\" width=\"600\" height=\"338\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "width": 600, "scrolling": false, "height": 338}, "subreddit": "Bad_Cop_No_Donut", "selftext_html": null, "selftext": "", "likes": null, "secure_media": {"oembed": {"provider_url": "http://www.youtube.com/", "description": "Video shows an officer tripping and pushing students rushing the field after Vandegrift High School's state soccer win Saturday. The Georgetown Police Department is investigating.", "title": "Officer trips, pushes students after soccer match; police investigating", "url": "http://www.youtube.com/watch?v=XAAgXaMCdfI", "type": "video", "author_name": "kxan", "height": 338, "width": 600, "html": "<iframe class=\"embedly-embed\" src=\"https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXAAgXaMCdfI%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXAAgXaMCdfI&image=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=text%2Fhtml&schema=youtube\" width=\"600\" height=\"338\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "thumbnail_width": 480, "version": "1.0", "provider_name": "YouTube", "thumbnail_url": "https://i.embed.ly/1/image?url=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=b1e305db91cf4aa5a86b732cc9fffceb", "thumbnail_height": 360, "author_url": "http://www.youtube.com/user/kxan"}, "type": "youtube.com"}, "link_flair_text": null, "id": "23kjd4", "gilded": 0, "secure_media_embed": {"content": "<iframe class=\"embedly-embed\" src=\"https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXAAgXaMCdfI%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXAAgXaMCdfI&image=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=text%2Fhtml&schema=youtube\" width=\"600\" height=\"338\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "width": 600, "scrolling": false, "height": 338}, "clicked": false, "stickied": false, "author": "mkultraman", "media": {"oembed": {"provider_url": "http://www.youtube.com/", "description": "Video shows an officer tripping and pushing students rushing the field after Vandegrift High School's state soccer win Saturday. The Georgetown Police Department is investigating.", "title": "Officer trips, pushes students after soccer match; police investigating", "url": "http://www.youtube.com/watch?v=XAAgXaMCdfI", "type": "video", "author_name": "kxan", "height": 338, "width": 600, "html": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2FXAAgXaMCdfI%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXAAgXaMCdfI&image=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=text%2Fhtml&schema=youtube\" width=\"600\" height=\"338\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "thumbnail_width": 480, "version": "1.0", "provider_name": "YouTube", "thumbnail_url": "http://i1.ytimg.com/vi/XAAgXaMCdfI/hqdefault.jpg", "thumbnail_height": 360, "author_url": "http://www.youtube.com/user/kxan"}, "type": "youtube.com"}, "score": 38, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "default", "subreddit_id": "t5_2qqdb", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "downs": 11, "saved": false, "is_self": false, "permalink": "/r/Bad_Cop_No_Donut/comments/23kjd4/officer_trips_pushes_students_after_soccer_match/", "name": "t3_23kjd4", "created": 1398087129.0, "url": "http://www.youtube.com/watch?v=XAAgXaMCdfI", "author_flair_text": null, "title": "Officer trips, pushes students after soccer match; police investigating", "created_utc": 1398058329.0, "ups": 49, "num_comments": 2, "visited": false, "num_reports": null, "distinguished": null}}, {"kind": "t3", "data": {"domain": "youtube.com", "banned_by": null, "media_embed": {"content": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2FXAAgXaMCdfI%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXAAgXaMCdfI&image=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=text%2Fhtml&schema=youtube\" width=\"600\" height=\"338\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "width": 600, "scrolling": false, "height": 338}, "subreddit": "news", "selftext_html": null, "selftext": "", "likes": null, "secure_media": {"type": "youtube.com", "oembed": {"provider_url": "http://www.youtube.com/", "description": "Video shows an officer tripping and pushing students rushing the field after Vandegrift High School's state soccer win Saturday. The Georgetown Police Department is investigating.", "title": "Officer trips, pushes students after soccer match; police investigating", "url": "http://www.youtube.com/watch?v=XAAgXaMCdfI", "author_name": "kxan", "height": 338, "width": 600, "html": "<iframe class=\"embedly-embed\" src=\"https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXAAgXaMCdfI%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXAAgXaMCdfI&image=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=text%2Fhtml&schema=youtube\" width=\"600\" height=\"338\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "thumbnail_width": 480, "version": "1.0", "provider_name": "YouTube", "thumbnail_url": "https://i.embed.ly/1/image?url=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=b1e305db91cf4aa5a86b732cc9fffceb", "type": "video", "thumbnail_height": 360, "author_url": "http://www.youtube.com/user/kxan"}}, "link_flair_text": null, "id": "23l967", "gilded": 0, "secure_media_embed": {"content": "<iframe class=\"embedly-embed\" src=\"https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXAAgXaMCdfI%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXAAgXaMCdfI&image=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=text%2Fhtml&schema=youtube\" width=\"600\" height=\"338\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "width": 600, "scrolling": false, "height": 338}, "clicked": false, "stickied": false, "author": "FictionFawkes", "media": {"type": "youtube.com", "oembed": {"provider_url": "http://www.youtube.com/", "description": "Video shows an officer tripping and pushing students rushing the field after Vandegrift High School's state soccer win Saturday. The Georgetown Police Department is investigating.", "title": "Officer trips, pushes students after soccer match; police investigating", "url": "http://www.youtube.com/watch?v=XAAgXaMCdfI", "author_name": "kxan", "height": 338, "width": 600, "html": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2FXAAgXaMCdfI%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXAAgXaMCdfI&image=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXAAgXaMCdfI%2Fhqdefault.jpg&key=2aa3c4d5f3de4f5b9120b660ad850dc9&type=text%2Fhtml&schema=youtube\" width=\"600\" height=\"338\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "thumbnail_width": 480, "version": "1.0", "provider_name": "YouTube", "thumbnail_url": "http://i1.ytimg.com/vi/XAAgXaMCdfI/hqdefault.jpg", "type": "video", "thumbnail_height": 360, "author_url": "http://www.youtube.com/user/kxan"}}, "score": 1, "approved_by": null, "over_18": false, "hidden": false, "thumbnail": "", "subreddit_id": "t5_2qh3l", "edited": false, "link_flair_css_class": null, "author_flair_css_class": null, "downs": 0, "saved": false, "is_self": false, "permalink": "/r/news/comments/23l967/video_officer_tripping_and_pushing_students/", "name": "t3_23l967", "created": 1398117833.0, "url": "http://www.youtube.com/watch?v=XAAgXaMCdfI", "author_flair_text": null, "title": "Video: officer tripping and pushing students rushing the field after Vandegrift High School's state soccer win Saturday. The Georgetown Police Department is investigating.", "created_utc": 1398089033.0, "ups": 1, "num_comments": 0, "visited": false, "num_reports": null, "distinguished": null}}], "after": null, "before": null}}

if there are no results then this will returned:

"{}"

from redditkit.rb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.