1

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
  1. 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.

  1. You need to enable write access for your application. I think you can use this question as registered Stack Apps post.

  2. Get an access token with write access, by following the steps described in Authentication.

  3. 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:

enter image description here

  1. Use the /posts/{id}/comments/add method to add a comment. You'll have to add the request key and access token obtained above. Be sure to set the preview parameter 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!

6
  • When I register for this post it says this error Post should be tagged [app] or [script] – Mohammed Noman Razvi Jan 13 at 12:40
  • For the time being, you can add either tag to the question. It's not officially an [app] or [script] post, but who cares ... – Glorfindel Jan 13 at 14:17
  • Now it says this kind of error { "error_id": 407, "error_message": "User does not have permission to comment on this post", "error_name": "write_failed" } – Mohammed Noman Razvi Jan 14 at 1:18
  • Then you did everything right (not a small feat!) except that (and I should have noticed that upfront) don't have the privilege to comment, except on your own posts and answers to your questions. – Glorfindel Jan 14 at 7:30
  • I am the owner of this post right? Ideally I should able to add a comment. But it says I not have permission to comment on this post... Wait a sec I am the owner of this post – Mohammed Noman Razvi Jan 14 at 9:54
  • Yes, you should be able to. Not sure why that wouldn't work ... – Glorfindel Jan 14 at 9:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .