YAFLogo

vcsharp
  • vcsharp
  • 88.4% (Honored)
  • YAF Commander Topic Starter
6 years ago
I am wanting to use Akismet for spam protection.

For this, I am trying to find some sample C# code in yaf.

So far, I have come up with the following just by looking at classes under the folder YAF.Core/Services/CheckforSpam, but not sure if my code below is correct .

Question: Can someone please provide correct sample code for using Akismet in yaf?

HttpClient httpClient = new HttpClient();

YAF.Core.Services.CheckForSpam.AkismetSpamClient akspClient = 
   new YAF.Core.Services.CheckForSpam.AkismetSpamClient("myKey", "http://www.myedu.com/forums/post", httpClient);


Comment comment = new Comment();
//set comment properties

//get whether comment is a spam
string response = akspClient.SubmitComment(comment, "http://www.myedu.com/forums/post");

//how do I now process response to check if comment was  spam?
Sponsor
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
6 years ago
You only need to enable it in the host settings, and enter the api key!
Sunil Dhaul
6 years ago
Thanks.

A related question: Will this api key host setting work on localhost, or it only works in a real live hosted scenario?

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
6 years ago
If I remember correctly the api key is only for one domain, but it will work also on localhost.

But i suggest you should better use the other more effective anti spam options in yaf. Akismet is not really helping. You can read more about the Anti Spam options in the documentation

https://github.com/YAFNET/YAFNET/wiki/Protect-YAF.NET-against-Spam-BOTS 

vcsharp
  • vcsharp
  • 88.4% (Honored)
  • YAF Commander Topic Starter
6 years ago
Thanks for your reply.

I think it will not work on a localhost since webserver on your local machine is not exposed to the world wide web. The Akismet server needs to be able to see your localhost webserver for it to send back a Http response and its not an easy task nowadays with most ISPs blocking a lot of things to localhost with complex router rules.

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
6 years ago

Thanks for your reply.

I think it will not work on a localhost since webserver on your local machine is not exposed to the world wide web. The Akismet server needs to be able to see your localhost webserver for it to send back a Http response and its not an easy task nowadays with most ISPs blocking a lot of things to localhost with complex router rules.

Originally Posted by: vcsharp 

No thats not correct. It will work. Yaf send the request to the akismet server, and not appositive. This will work on localhost

vcsharp
  • vcsharp
  • 88.4% (Honored)
  • YAF Commander Topic Starter
6 years ago
You are right. One can connect to Akismet from localhost since its a simple post request to Akismet that can be made from C# code.

I tried this and I was able to post to Akismet from code-behind.