Topic on Project:Support desk

Getting invalid token error even after sending the correct edit token while upload image using API

4
Senthilnathan Murthy (talkcontribs)

Hi,

I'm trying to edit a page and upload an image using Mediawiki API call.

I've logged in as user. I've fetched the edit token using below code: $editToken = urlencode($wgUser->editToken($salt=,$request = $wgRequest));

Below is the post data I'm passing to upload an image using Mediawiki Api, $imgUploadData = "filename=Wiki.png&token=%2B%5C&url=http%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fen%2Fb%2Fbc%2FWiki.png";

Below is the curl call to execute the api,

$submitUrl = "http://example.com/api.php?action=upload&format=json";
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $submitUrl);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $imgUploadData);
$objData = curl_exec($curlObj);
curl_close($curlObj);

return $objData;

When executing the API call its giving the error as below,

<api>
  <error code="badtoken" info="Invalid token" xml:space="preserve">
</error>
</api>

I'm getting the error as "badtoken" token even after sending the proper edit token. Can you please help me out to sort this issue. I'm struck with this for the past 1

week.

Ciencia Al Poder (talkcontribs)

Where are you sending the cookies in your curl request?

223.227.17.130 (talkcontribs)

Was this issue resolved? I am also stuck with this issue and not able to do any progress. I am calling the API from a Java program

Ciencia Al Poder (talkcontribs)

You should store the cookies retrieved from the login request, and send them on all subsequent requests

Reply to "Getting invalid token error even after sending the correct edit token while upload image using API"