Je veux utiliser Mediawiki api pour enregistrer l'utilisateur, je veux utiliser une boucle pour des appels api, j'ai essayé avecComment utiliser boucle avec l'API MediaWiki pour inscrire
function RegisterCurl()
{
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
//$url = 'http://localhost/WC/gccfwiki/api.php';
$myvar1 = "createaccount";
$myvar2 = "http://localhost/WC/gccfwiki/";
$myvar3 = $this->GetToken;
// $remove = '+\\';
// $myvar3 = str_replace($remove,"",$myvar3);
$myvar4 = "Bob";
$myvar5 = "ExamplePassword";
$myvar6 = "ExamplePassword";
$myvar7 = "[email protected]";
$myvar8 = "Robert20Example";
$myvars = 'action=' . $myvar1 . '&createreturnurl=' . $myvar2 . '&createtoken=' . $myvar3 . '&username=' . $myvar4. '&password=' . $myvar5 . '&retype=' . $myvar6 . '&email=' . $myvar7 . '&realname=' . $myvar8;
$url = 'http://localhost/WC/gccfwiki/api.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 25);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
var_dump($output);
die();
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
public function GetToken()
{
$url = 'http://localhost/WC/gccfwiki/api.php?action=query&format=json&meta=tokens&type=csrf|createaccount';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
$out=json_decode($output);print_r($out);die();
$token = $out->query->tokens->createaccounttoken;
return $token;
}
je suis la réponse { "error": { "code": "badtoken", "info": "Jeton CSRF non valide.", "*": "Voir http://localhost/WC/gccfwiki/api.php pour l'utilisation de l'API S'abonner à la liste de diffusion mediawiki-api-announce au < https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce>, pour la notification des dépréciations de l'API et des modifications de rupture. " } }
est-il une solution .. comment je le résoudre ???
Êtes-vous marié à l'idée d'utiliser Curl directement? Parce que vous pourriez utiliser la bibliothèque 'addwiki/mediawiki-api' à la place, et ce serait beaucoup plus simple! :-) –
J'ai besoin d'appeler curl d'un projet différent au wiki ... – Midlaj
Oui, mais dans ce projet, vous pourriez faire, par exemple, '$ userCreator() -> create ('Nom d'utilisateur', 'pwd123');' et toute la complexité serait traitée pour vous par https://github.com/addwiki/mediawiki-api –