I'm trying to allow a bot to log in using the en.wikipedia API.
As the OAuth authenticator doesn't seem to work (it presents captchas when it should not, but that's another story), I'm regressing to using a bot password.
I'm following the instructions at https://www.mediawiki.org/wiki/API:Login , replicated in the API documentation.
I can obtain a login token readily using
$response = json_decode($this->fetch(API_ROOT, array('action' => 'query', 'meta'=>'tokens', 'type'=>'login')));
But this login token is not recognized by the next step:
$lgVars = ['action' => 'login', 'lgname' => WP_USERNAME, 'lgpassword' => WP_PASSWORD, 'lgtoken' => $response->query->tokens->logintoken, ]; $response = json_decode($this->fetch(API_ROOT, $lgVars, 'POST'));
produces:
object(stdClass)#205 (2) {
["warnings"]=> object(stdClass)#211 (2) { ["main"]=> object(stdClass)#212 (1) { ["*"]=> string(267) "Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes. Use [[Special:ApiFeatureUsage]] to see usage of deprecated features by your application." } ["login"]=> object(stdClass)#213 (1) { ["*"]=> string(101) "Fetching a token via "action=login" is deprecated. Use "action=query&meta=tokens&type=login" instead." } } ["login"]=> object(stdClass)#204 (2) { ["result"]=> string(9) "NeedToken" ["token"]=> string(42) "b1621a8fa099ce7404b15d4e68ec5b165a22e6bd+\" }
}