API talk:Tokens

I only get '+\' as an csrf-token
Please, can somebody help me?--Mischa004 (talk) 18:14, 16 February 2015 (UTC)

My PHP-code:

$parameters = array('action' => 'query', 'meta' => 'tokens', 'format' => 'json'); $options = array(   'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($parameters), ), ); $context = stream_context_create($options); $result = file_get_contents($wiki, false, $context); echo "$result";


 * That's how the token currently looks what you're not logged in (although there are plans to use real token for anonymous users too). Nothing to worry about. Matma Rex (talk) 20:19, 16 February 2015 (UTC)
 * Thank you! In fact, I really want to have a token to edit as a registered user. Before obtaining the token as shown above I login with this PHP-code:

$parameters = array('action' => 'login', 'lgname' => 'mischa', 'lgpassword' => 'PASSWORD', 'format' => 'json'); $options = array(   'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($parameters), ), ); $context = stream_context_create($options); $result = file_get_contents($wiki, false, $context);


 * Note: $wiki can be for example http://en.wikipedia.org/w/api.php --Mischa004 (talk) 20:29, 16 February 2015 (UTC)
 * Looks like you're not passing the cookies from the first request to the second one? I'm afraid I have no idea how that's done in PHP, though. Matma Rex (talk) 20:51, 16 February 2015 (UTC)
 * Thank you! I have to check this the day after tomorrow,--Mischa004 (talk) 20:56, 16 February 2015 (UTC)