简体   繁体   中英

Mediawiki api login doesn't accept token

I'm trying to authenticate to the mediawiki api, but it doesn't accept the login token I requested. When I request (via POST) the token like this action=query&meta=tokens&type=login&format=json it returns me aa token, for example

batchcomplete:
query: {
    tokens: {
        logintoken: af69aa46ef0e505dca1b4b0ea696a55259258b4f+\
    }
}

But when I now try to authenticate with action=login&lgname=user&lgpassword=password&lgtoken=af69aa46ef0e505dca1b4b0ea696a55259258b4f%2B%5C&format=json I only getting this message back

warnings: {
    main: {
        *: Subscribe to the mediawiki-api-announce mailing list at for notice of API deprecations and breaking changes. Use [Special:ApiFeatureUsage]] to see usage of deprecated features by your application.
    }
    login: {
        *: Fetching a token via "action=login" is deprecated. Use "action=query&meta=tokens&type=login" instead.
    }
}
login: {
    result: NeedToken
    token: a26aa15ecc99c421db73b86e7581497959258b4f+\
}

It seems like it's not recognizing the token. I'm using a bot password to login.

Thanks for your help

Simon

Tgr's comment solved my question:

You need to issue the requests in the same session.

How can I use sessions in a php script?

Depends on what you use for making web requests. With curl, you need to use the cookie jar + cookie file options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM