User:Liz Kariuki/Sandbox/API:Linkaccount
| MediaWiki Action API |
|---|
| Basics |
| Authentication |
| Accounts and Users |
| Page Operations |
|
| Search |
| Developer Utilities |
| Tutorials |
| v · d · e |
Link an account from a third-party provider to the current user.
API documentation
[edit ]action=linkaccount (link)
- This module requires write rights.
- This module only accepts POST requests.
- Source: MediaWiki
- License: GPL-2.0-or-later
Link an account from a third-party provider to the current user.
The general procedure to use this module is:
- Fetch the fields available from action=query&meta=authmanagerinfo with amirequestsfor=link, and a csrf token from action=query&meta=tokens .
- Present the fields to the user, and obtain their submission.
- Post to this module, supplying linkreturnurl and any relevant fields.
- Check the status in the response.
- If you received PASS or FAIL, you're done. The operation either succeeded or it didn't.
- If you received UI, present the new fields to the user and obtain their submission. Then post to this module with linkcontinue and the relevant fields set, and repeat step 4.
- If you received REDIRECT, direct the user to the redirecttarget and wait for the return to linkreturnurl. Then post to this module with linkcontinue and any fields passed to the return URL, and repeat step 4.
- If you received RESTART, that means the authentication worked but we don't have a linked user account. You might treat this as UI or as FAIL.
- linkrequests
Only use these authentication requests, by the id returned from action=query&meta=authmanagerinfo with amirequestsfor=link or from a previous response from this module.
- Separate values with | or alternative.
- Maximum number of values is 50 (500 for clients that are allowed higher limits).
- linkmessageformat
Format to use for returning messages.
- One of the following values: html, none, raw, wikitext
- Default: wikitext
- linkmergerequestfields
Merge field information for all authentication requests into one array.
- Type: boolean (details)
- linkreturnurl
Return URL for third-party authentication flows, must be absolute. Either this or linkcontinue is required.
Upon receiving a REDIRECT response, you will typically open a browser or web view to the specified redirecttarget URL for a third-party authentication flow. When that completes, the third party will send the browser or web view to this URL. You should extract any query or POST parameters from the URL and pass them as a linkcontinue request to this API module.
- linkcontinue
This request is a continuation after an earlier UI or REDIRECT response. Either this or linkreturnurl is required.
- Type: boolean (details)
- linktoken
A "csrf" token retrieved from action=query&meta=tokens
- This parameter is required.
- *
- This module accepts additional parameters depending on the available authentication requests. Use action=query&meta=authmanagerinfo with amirequestsfor=link (or a previous response from this module, if applicable) to determine the requests available and the fields that they use.
- Start the process of linking to an account from Example.
- api.php?action=linkaccount&provider=Example&linkreturnurl=http://example.org/&linktoken=123ABC [open in sandbox]
Examples
[edit ]Example 1: Fetch all the links in a page
[edit ]GET request
[edit ]{==== Response ====
{ "query":{ "pages":[ { "pageid":736, "ns":0, "title":"Albert Einstein", "links":[ { "ns":0, "title":"2dF Galaxy Redshift Survey" }, { "ns":0, "title":"A priori and a posteriori" }, { "ns":0, "title":"Aage Bohr" }, ... ] } ] } }
Sample code
[edit ]User:Liz Kariuki/Sandbox/API:Linkaccount/Sample code 1
Example 2: Fetch missing links
[edit ]Get request to fetch missing or red links on Wikipedia:Most-wanted_articles. Two steps to do so:
- Make a
GETrequest to the Action API to return all links embedded on the provided page. - From further extraction, obtain those links that are missing and don't yet exist on English Wikipedia.
generator=links query module's submodule links used as a generator module to get a set of links embedded on a page.GET request
[edit ]Response
[edit ]| Response |
|---|
{ "batchcomplete":"", "continue":{ "continue":"gplcontinue||", "gplcontinue":"297177|0|1965_in_sumo" }, "query":{ "pages":{ "-1":{ "missing":"", "ns":0, "title":"(viii)" }, "-10":{ "missing":"", "ns":0, "title":"1954 in sumo" } ... } } } |
Sample code
[edit ]| get_red_links.py |
|---|
Parameter history
[edit ]- v1.19: Introduced
pldir - v1.17: Introduced
pltitles - v1.13: Introduced
pllimit,plcontinue
See also
[edit ]- API:Linkshere - API:Properties submodule that finds pages which include a link to the given page.
- API:Backlinks - API:Lists submodule that gets a list of pages which link to a given page.
- API:Iwlinks - Find interwiki links on a given page (i.e, meta pages, special pages).
- API:Iwbacklinks - Get a list of pages which are linked from a given interwiki link.
- API:Extlinks - Find all external links on a given page.
- API:Exturlusage - Get all pages that link to an external URL.
- API:Langlinks - Get a list of language links from the given page. Language links represent translations.
- API:Langbacklinks - Get a list of pages that contains a given language link.