Dear community,
I have been stuck with this problem for quite sometime, I have been trying to use the upload api and have tried the example specified on the page. And I've been getting the error: badtoken and info: invalid token.
I couldn't get it to work. I have followed the said steps. First get the token. The result was as follows.
{"query":{"normalized":[{"from":"Test_Page","to":"Test Page"}],"pages":{"2":{"pageid":2,"ns":0,"title":"Test Page","touched":"2012-06-05T16:09:33Z","lastrevid":2,"counter":3,"length":12,"new":"","starttimestamp":"2012-06-15T14:43:02Z","edittoken":"a25a10589a377fc4d75e5e0dcfb209c2+\"}}}}
Then tried uploading the file.
$params = array( 'action' => 'upload', 'url' => 'http://www.google.com/intl/en_ALL/images/logo.gif', 'token' => "a25a10589a377fc4d75e5e0dcfb209c2%2B%5C", 'format' => 'json' );
I keep getting the error as follows. {"error":{"code":"badtoken","info":"Invalid token"}}
Where is it that I am going wrong ?
On Fri, Jun 15, 2012 at 7:46 AM, Suryajith Chillara suryajith1987@gmail.com wrote:
'token' => "a25a10589a377fc4d75e5e0dcfb209c2%2B%5C",
You're probably double-encoding the token here, I'll bet that whatever library you're using will transmit this as "a25a....c2%252B%252C". So try using a literal +\ in the token parameter and let the library handle the escaping for you.
Roan
You're probably double-encoding the token here, I'll bet that whatever library you're using will transmit this as "a25a....c2%252B%252C". So try using a literal +\ in the token parameter and let the library handle the escaping for you.
Roan, thanks for the reply. This is what I've observed when I printed $_POST variable.
1. When I let the token be sent as +, the post parameters were Array ( [action] => upload [url] => http://www.google.com/intl/en_ALL/images/logo.gif [token] => a25a10589a377fc4d75e5e0dcfb209c2 \ [format] => json )
2. When I encode +\ and send the token, the post parameters were Array ( [action] => upload [url] => http://www.google.com/intl/en_ALL/images/logo.gif [token] => a25a10589a377fc4d75e5e0dcfb209c2+\ [format] => json )
Thus, I started using them. This was just a curl call made through php.
Thanks,
escape the + + possibly and leave the \ alone
On Fri, Jun 15, 2012 at 11:12 AM, Suryajith Chillara < suryajith1987@gmail.com> wrote:
You're probably double-encoding the token here, I'll bet that whatever
library you're using will transmit this as "a25a....c2%252B%252C". So try using a literal +\ in the token parameter and let the library handle the escaping for you.
Roan, thanks for the reply. This is what I've observed when I printed $_POST variable.
- When I let the token be sent as +, the post parameters were
Array ( [action] => upload [url] => http://www.google.com/intl/en_**ALL/images/logo.gifhttp://www.google.com/intl/en_ALL/images/logo.gif [token] => a25a10589a377fc4d75e5e0dcfb209**c2 \ [format] => json )
- When I encode +\ and send the token, the post parameters were
Array ( [action] => upload [url] => http://www.google.com/intl/en_**ALL/images/logo.gifhttp://www.google.com/intl/en_ALL/images/logo.gif [token] => a25a10589a377fc4d75e5e0dcfb209**c2+\ [format] => json )
Thus, I started using them. This was just a curl call made through php.
Thanks,
-- Regards, Suryajith Chillara.
______________________________**_________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.**org Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/**mailman/listinfo/mediawiki-apihttps://lists.wikimedia.org/mailman/listinfo/mediawiki-api
when passing parameters "+" is often treated as " " (a space) try passing "+" instead of "+" or what ever the equivalent escape is
On Fri, Jun 15, 2012 at 11:16 AM, Suryajith Chillara < suryajith1987@gmail.com> wrote:
On 06/16/2012 02:15 AM, Betacommand wrote:
escape the + + possibly and leave the \ alone
Sorry, I did not get you there. Could you please elaborate it.
Thanks,
-- Regards, Suryajith Chillara.
______________________________**_________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.**org Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/**mailman/listinfo/mediawiki-apihttps://lists.wikimedia.org/mailman/listinfo/mediawiki-api
On 06/16/2012 02:19 AM, Betacommand wrote:
when passing parameters "+" is often treated as " " (a space) try passing "+" instead of "+" or what ever the equivalent escape is
That doesn't seem to help either, the token recieved by api.php via the urlencoded a25a10589a377fc4d75e5e0dcfb209c2%2B%5C instead of a25a10589a377fc4d75e5e0dcfb209c2+\ or a25a10589a377fc4d75e5e0dcfb209c2+\ shows the token to be something else when $_POST is printed out. Array ( [action] => upload [url] => http://www.google.com/intl/en_ALL/images/logo.gif [token] => a25a10589a377fc4d75e5e0dcfb209c2+\ [format] => json ) compared to Array ( [action] => upload [url] => http://www.google.com/intl/en_ALL/images/logo.gif [token] => a25a10589a377fc4d75e5e0dcfb209c2+\ [format] => json )
or
Array ( [action] => upload [url] => http://www.google.com/intl/en_ALL/images/logo.gif [token] => a25a10589a377fc4d75e5e0dcfb209c2\ \ [format] => json )
respectively.
Thanks,
On 15/06/12 22:49, Betacommand wrote:
when passing parameters "+" is often treated as " " (a space) try passing "+" instead of "+" or what ever the equivalent escape is
Parameters will need to be urlescaped. Which will convert + into %2B. Note that if you don't properly urlescape the parameters, when you edit a page you will corrupt its content.
mediawiki-api@lists.wikimedia.org