Disqus API: create a comment as a guest

I am trying to use the Disqus API to add a post to an existing forum / forum. In the documentation, I can read that I can send a comment without authentication as a guest. The documentation says the following: http://disqus.com/api/docs/posts/create/

Anonymous comments are allowed in two conditions:

  • You are using obsolete auth and your secret key
  • You use your public key, you came from a trusted referrer, you are not authenticated, and the forum where you are trying to create a message is listed in the trusted application forums.

To create an anonymous comment, simply pass author_email and author_name and, optionally, the author_url parameter.

Therefore, I use this code to create a comment in PHP. (I use a very simple cURL class, but there is no problem there, because I get the same in the console at disqus.com/api)

$curl = new Curl(1); $curl->addPostVar('thread','THREAD_ID'); $curl->addPostVar('message','Text message'); $curl->addPostVar('author_email','My email'); $curl->addPostVar('author_name','My name'); $curl->addPostVar('api_secret','My application secret API key'); echo $curl->exec('https://disqus.com/api/3.0/posts/create.json'); 

But I get an error via JSON

 {"code": 4, "response": "You must be authenticated to perform this action"} 

I know that someone else asked this ( Disqus API to create an error message ), but the answer suggested using OAuth and getting authentication. But I do not want to authenticate, I want to send a comment for guests with a name and email. Where am I mistaken?

Thanks so much for any answers.

+4
source share
3 answers

To comment anonymously, you might not pass access tokens. However, you must ensure that the following conditions are true:

  • In the settings of your website in the "General" section, make sure that "Allow guest comments" is checked.
  • In the settings of your Disqus site on the "Advanced" tab, add your domain as trusted domains
  • In the API application settings, add the same domains from trusted domains to the list of trusted domains of API applications
  • When you make an API request to post a comment, make sure that the "referer" header has a domain that is on one of these trusted domains and set the "host" header to ".disqus.com" for a good rating
  • Make an API request using the public key

I was able to successfully complete the request with these rules.

To make this clear, you will need to own / moderate the site in order to post anonymous comments via the API. Also make sure you pass the optional argument strict=1 when you do this. By default, any optional arguments that the error is simply deleted, so you can potentially encounter a situation where comments are posted as if the author_name and author_email throw an error.

+2
source

After checking the obvious things (for example, enabling guest posting and checking my link domains in the forum and application settings), I was finally able to solve this problem using disqus-php :

 require __DIR__ . '/disqus-php-master/disqusapi/disqusapi.php'; $disqus = new DisqusAPI($secret_key); print_r($disqus->posts->create(array( 'thread' => $thread_id, 'message' => $message, 'author_name' => $author_name, 'author_email' => $author_email, 'api_key' => $api_key, ))); 

The conclusion is that api_key NOT ONLY the public key specified in the settings of your Disqus application. I really needed to check one of the AJAX calls from the Disqus Javascript widget to get the correct api_key :

Disqus AJAX call headers showing the api_key

+2
source

I re-open this thread because I have the same question and it seems that there is no answer to it yet.

I have been trying for several days to make comments via the API as a guest. If I read the API documentation, I will say that I need to pass the message, author_name, author_url, thread and api_key to do this, but I can not do it. I always get

 "Code: 12" 

and

 "This application cannot create posts on the chosen forum". 

If I send via access_token, this will work, but then it will be published as I do, and I do not want this.

I also found Disqus recipes on Github and in the readme file in the Beginner section it refers to a snippet

"Create a comment for guests: /php/create-guest-comment.php"

but cannot find the fragment. Therefore, I look through the commits and find "Delete stale guest comment creation script" . Should I take this as a hint that Disqus cannot currently create comments as a guest through the API? If so, Disqus may update your documentation.

If I do something wrong, I would appreciate if you point me in the right direction.

+1
source

Source: https://habr.com/ru/post/1469325/


All Articles