Sai Krishna
Sai Krishna

Reputation: 557

Reddit json api behaves differently when access it through a browser and nodejs request

I'm trying to access secure_media property of a post to download a v.redd.it media.

For example: when I try to access this link from a browser, the secure_media property is not empty in the response, but when i GET it through nodejs request the secure_media is empty

Upvotes: 1

Views: 221

Answers (1)

justcool393
justcool393

Reputation: 247

The issue here is that you are dealing with a crosspost submission, not the actual submission itself, which work a bit differently from normal submissions.

You can get the video information from the secure_media property of the first item in the crosspost_parent_list property. Here is part of the JSON structure for the post you linked:

[
  {
    "kind": "Listing",
    "data": {
      "modhash": "yg3o3tzdc136d53e2919218e00ef74e8fc38d97b9a22f34b60",
      "dist": 1,
      "children": [
        {
          "kind": "t3",
          "data": {
            "secure_media": null,
            "is_reddit_media_domain": true,
            "is_meta": false,
            "category": null,
            "num_comments": 9,
            "secure_media_embed": {},
            "crosspost_parent_list": [
              {
                "secure_media": {
                  "reddit_video": {
                    "fallback_url": "https://v.redd.it/kh2kirut06731/DASH_1080?source=fallback",
                    "height": 1080,
                    "width": 608,
                    "scrubber_media_url": "https://v.redd.it/kh2kirut06731/DASH_96",
                    "dash_url": "https://v.redd.it/kh2kirut06731/DASHPlaylist.mpd",
                    "duration": 53,
                    "hls_url": "https://v.redd.it/kh2kirut06731/HLSPlaylist.m3u8",
                    "is_gif": true,
                    "transcoding_status": "completed"
                  }
                },
                "is_reddit_media_domain": true,
                "discussion_type": null,
                "mod_reports": [],
                "is_video": true
              }
            ],
            "created": 1561824841,
            "link_flair_type": "text",
            "wls": 6,
            "banned_by": null,

Upvotes: 1

Related Questions