I want to add an comment to a specific post so, how do I get its ID and how do I authorize it. I want it to done through the Stack Exchange API interface.
1 Answer
- For posting comments, you need a request key for your application:
Applications should be registered on Stack Apps to get a request key. Request keys grant more requests per day, and are necessary for using access_tokens created via authentication.
You need to enable write access for your application. I think you can use this question as registered Stack Apps post.
Get an access token with write access, by following the steps described in Authentication.
To find the ID of a post, click the share link and copy the first number after
/q/or/a/. The ID of your question is 8833:
- Use the
/posts/{id}/comments/addmethod to add a comment. You'll have to add the request key and access token obtained above. Be sure to set thepreviewparameter to false; otherwise, it looks like it creates a comment but doesn't actually do it.
You can use posts in the API sandbox or one of your own questions to test; remember that comments cause notifications and you don't want to needlessly ping users. Good luck!
