Verifica della chiave
La verifica della chiave autentica la tua chiave prima di chiamare i metodi comment-check, submit-spam o submit-ham per la prima volta. Questa è la prima chiamata che dovresti fare ad Akismet ed è particolarmente utile se la tua applicazione è usata da più utenti con un proprio abbonamento Akismet.
Nota bene che non è necessario chiamare questo metodo prima di ogni chiamata a comment-check, submit-spam o submit-ham. Fai questa richiesta solo per confermare la validità di una chiave API prima di memorizzarla localmente.
Questo metodo viene chiamato con una richiesta POST all’URL qui sotto:
https://rest.akismet.com/1.1/verify-key
Parametri richiesti
api_key
La tua chiave API di Akismet. Puoi trovarla nella bacheca del tuo account su: https://akismet.com/account/
blog
L’URL della pagina principale o home dell’istanza che effettua la richiesta. Per un blog o una wiki, è la pagina principale. Nota bene: deve essere un URI completo, con http:// incluso.
Esempio in PHP
// Chiamata alla funzione di verifica della chiave
akismet_verify_key('123YourAPIKey', 'http://www.yourblogdomainname.com/');
// Autentica la tua chiave API Akismet
function akismet_verify_key( $key, $blog ) {
$blog = urlencode($blog);
$request = 'key='. $key .'&blog='. $blog;
$host = $http_host = 'rest.akismet.com';
$path = '/1.1/verify-key';
$port = 443;
$akismet_ua = "WordPress/4.4.1 | Akismet/3.1.7";
$content_length = strlen( $request );
$http_request = "POST $path HTTP/1.0rn";
$http_request .= "Host: $hostrn";
$http_request .= "Content-Type: application/x-www-form-urlencodedrn";
$http_request .= "Content-Length: {$content_length}rn";
$http_request .= "User-Agent: {$akismet_ua}rn";
$http_request .= "rn";
$http_request .= $request;
$response = '';
if( false != ( $fs = @fsockopen( 'ssl://' . $http_host, $port, $errno, $errstr, 10 ) ) ) {
fwrite( $fs, $http_request );
while( !feof( $fs ) ) {
$response .= fgets( $fs, 1160 ); // One TCP-IP packet
}
fclose( $fs );
$response = explode( "rnrn", $response, 2 );
}
if ( 'valid' == $response[1] ) {
return true;
} else {
return false;
}
}
Esempio di risposta positiva
La chiamata restituisce valid se la chiave è valida.
Array (
[0] => HTTP/1.1 200 OK
Server: nginx
Date: Mon, 24 Feb 2014 16:31:55 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
Content-length: 5
[1] => valid
)
Esempio di risposta di errore
Se la chiamata verify-key restituisce “invalid”, di solito include un’intestazione HTTP aggiuntiva con alcune informazioni di debug che descrivono cos’è che era invalido nella chiamata.
Array (
[0] => HTTP/1.1 200 OK
Server: nginx
Date: Mon, 24 Feb 2014 16:34:54 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
X-akismet-debug-help: We were unable to parse your blog URI
Content-length: 7
[1] => invalid
)
Siamo qui per aiutarti
Se sei difficoltà o hai bisogno di aiuto, non esitare a contattarci.
