Reddit Endpoint for comments for a particular article - reddit

I am trying to get all of the reddit comments for a particular article.
On the Reddit API page, it seems to suggest that:
www.reddit.com/r/subreddit/comments/ARTICLE
will get me these results (article being a variable), however if I go to an endpoint with the article appended after comments, all I get is a 404 error.
How do you get comments from a specific article via the Reddit API?
I'm doing this in Javascript, but this is obviously a language agnostic question.

reddit's generated API documentation for the comments endpoint appears to be incorrect. The correct URL to use to retrieve comments for a post is:
https://www.reddit.com/r/{subreddit}/comments/{article ID}/irrelevant_string.json
Or for a specific comment:
https://www.reddit.com/r/{subreddit}/comments/{article ID}/irrelevant_string/{comment ID}.json
The "irrelevant string" can be just an underscore, it doesn't matter - on the website itself, it's a form of the title, but the API doesn't care about the title of the post.

I know this is an older post, but I'm posting because I found this when I encountered a similar 404 error when requesting the official api comments endpoint, and while the accepted solution works you can still use reddit's generated api documentation for requesting comments using oauth.
My error (and I'm guessing OP's too) was not stripping the t3_ type prefix from ARTICLE's full name. For example,https://oauth.reddit.com/r/pics/comments/t3_zmvmpn returns a 404, but https://oauth.reddit.com/r/pics/comments/zmvmpn successfully returns the expected comment json.
It's easy to confuse because the official documentation isn't clear on when to use a thing's name vs its id, but when using the json the id field holds the necessary string without the type prefix.
The format when requesting the comments for a given ARTICLE (link) is:
https://oauth.reddit.com/comments/{id}
You can specify the subreddit if you want like in my other examples, but it's not required.

Related

Unable to get all comments of conversation thread of planner task

i am currently working on small project where i have to retrieve all comments of particular task in planner api (microsoft planner).
using microsoft graph api documentation link
i tried to call below end points
https://graph.microsoft.com/v1.0/groups/[GroupID]/threads/[ConversationID]
i replaced groupid and conversationId in above url and it works.
but it has two problem
1.) it return only one comment (recent comment), but i want to retrieve all comments.
2.) it shows only 250 character of comment (preview text), but i need to retrieve full comment.
can anyone help why api link give above two problem.
thank you
/posts will give you access to all the comments in a JSON array, and will have the full comment. However the comment will have HTML embedded in the data.
https://graph.microsoft.com/v1.0/groups/[GroupID]/threads/[ConversationID]/posts
HTH

Get information about the expected syntax of a string in the request body

I have been given a Swagger API with a request body defined as
{
"SqlFilterList": "string",
"SubjectKey": 0,
"SubjectCwaListingKey": 0
}
The programmer who wrote the API is on vacation and can't be reached. I don't have access to the API code. Is there in general anyway to interrogate the api to determine what the valid values of "string" might be? Or do I have to wait for the person to come back to the office?
I have reviewed the API's documentation via its URL (which is why I know that it needs a string), I searched the Swagger website and I searched questions with tag [swagger] in stackoverflow and didn't spot anything.
If the answer is that I am out of luck (which I strongly suspect to be true) is there a way that I can suggest to the author to document the valid syntax of the "string" in the API so that the next person doesn't go through this?
It sounds like you have found your way to the Swagger-UI, displaying the API documentation and interactive "try it out" buttons.
Most likely, the API is just not documented as thoroughly as you need it to be. But there's a chance you might be able to find more information from the Swagger spec. A couple of things you can do to dig deeper:
Look at the Request Model
In the Swagger-UI, click the "model" tab in the operation header:
This will display additional details about the request structure, if the developer has provided property-level descriptions. The misnamed "model schema" tab that displays by default is really an auto-generated example of the message structure; not so useful if you're looking for detailed request documentation.
Inspect the Swagger Source
You might be able to inspect the Swagger source specification that is populating the Swagger-UI. Try using the "view source" command in your browser, and look for the SwaggerUi object constructor. It will look something like this:
var swaggerUi = new SwaggerUi({
url: 'http://petstore.swagger.io/v2/swagger.json',
dom_id: 'swagger-ui-container'
});
Follow the specified url to find the source Swagger spec, and see if there is any further information available. It's unlikely that you'll find more there than what's displayed in the Swagger-UI, but it's worth a shot.
Note that there's another form of the SwaggerUi constructor that doesn't use a url property. Instead, it uses a spec property whose value is a (big!) JSON object. You can copy-paste that object into a Swagger or JSON editor (for easier reading with auto-format, syntax coloring, etc.) and see if there's any further info there.
If the answer is that I am out of luck (which I strongly suspect to be true) is there a way that I can suggest to the author to document the valid syntax of the "string" in the API so that the next person doesn't go through this?
Hopefully the API developer has provided a feedback channel, either through email or a support site. There might be some API documentation widgets that incorporate feedback or discussions directly, but Swagger-UI does not at this time, AFAIK.

Missing video ID from comment object

I am trying to retrieve a comment on a video by comment ID using the youtube v3 data api.
Here's the documentation part I am concerned with: https://developers.google.com/youtube/v3/docs/comments#resource
In the resource documentation, there's a property called "videoId" that I don't get when using this API call:
https://www.googleapis.com/youtube/v3/comments?part=snippet,id&key={YOUR_KEY_HERE}&id=z13cdfiygorrst1f422fuzi5eqevcdwsf
Edit: I have already been trying working around this problem to no avail, also started an issue on google issue tracker to no answer. As far as I know, the youtube-data-api tag is where the developers track the issues in the API.
I am not sure why the comments endpoint does not return the videoId, but the commentThreads does.
So calling https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,id&key={YOUR_KEY_HERE}&id=z13cdfiygorrst1f422fuzi5eqevcdwsf and parsing the result to get the proper comment in the comment threads (that includes replies) seems like a reasonable workaround...

How to get links in comments from the YouTube api following the move to Google+ comments

In the new YouTube Google + comments system how can I retrieve comments that contain links.
For example if someone posts a link to another youtube video as follows:
http://www.youtube.com/watch?v=AZNHuFjnmUo
This gets converted to a link by the google plus system. The title of the video is shown as the text rather that the url. i.e. The html shown within the comments is this:
Francis HATES Google+
However the api for that comment only returns the title of the video which is pretty useless seeing as I want to get the link too. I am guessing that the system converts the url into an <a> tag which is stored in the database but then the api strips out the html when its requested so it only returns the videos title.
I have posted a defect here:
https://code.google.com/p/gdata-issues/issues/detail?id=5500
But that bug list seems to have very little activity going on in terms of responses to issues.
So is there another way to get the data I need?
What you can do while this bug remains is to extract the comment id and use it in the Google+ API with an activities.get request. This will return the full post with all links.
A bit cumbersome since it needs one request for each comment you want to check, but it seems to be the only way while the bug remains.
To take an example from the video you linked in the issue:
This YouTube comment returned by the API includes a YouTube link:
http://gdata.youtube.com/feeds/api/videos/rgkDKeSc-1o
/comments/z12hvvcgxznkufyo304ci1iqlnandzxjpes
You can use the z... ID in a request to the Google+ API:
https://developers.google.com/apis-explorer/#p/plus/v1/plus.activities.get?activityId=z12hvvcgxznkufyo304ci1iqlnandzxjpes
Which includes the full post including links.

What is the best practice for restful urls?

I have a java based rest server, and my clients will be using Ruby mostly.
What is considered the best practice for URL structure?
This is for JSON only.
Say this is a blog application:
e.g.:
Get all posts:
GET http://www.example.com/api/v1/posts.json
Delete post with id 1:
DELETE http://www.example.com/api/v1/posts/1.json
What about embedded collections like:
Get all comments for post 1:
GET http://www.example.com/api/v1/posts/1/comments.json
View post 1's comment with id 1:
GET http://www.example.com/api/v1/posts/1/comments/1.json
Is there a document that goes over this somewhere? Something fairly "official"?
Apigee has a free e-book on RESTful API design. You have to supply an email address to get it:
http://offers.apigee.com/api-design-ebook-rr/
You're going to find this is a matter of opinion, with no official spec, but your URLs look good to me, and would be in accordance with the guidelines in that book. The possible exception being the last. If 1 is the unique ID of a comment, /posts/1/ may not be necessary.
You could start with the paper that coined REST and look at the URI section:
http://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm#sec_6_2
Bob Aman's well-regarded 2nd answer to this SO question gives detailed guidance:
How to create REST URLs without verbs?
Correctly using the HTTP protocol is the best idea. Read some about the url versioning. http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http

Resources