维基百科api不会返回请求ID

时间:2016-12-30 18:13:06

标签: javascript ajax wikipedia-api wikimedia

我试图向维基百科发出几个Ajax请求。 Ajax调用是for循环(JavaScript),这是一个问题,因为它们返回乱序。为了解决这个问题,我想我会在Ajax请求中包含一个请求ID,因为它是沙盒中的一个选项。问题是ID没有返回......?

(来自维基媒体' s sandbox

https://en.wikipedia.org/wiki/Special%3aApiSandbox#action=opensearch&format=json&requestid=12&search=clownfish

返回:

[
    "clownfish",
    [
        "Clownfish",
        "Clown"
    ],
    [
        "To the scientific name of an organism: This is a redirect from a vernacular (\"common\") name to the scientific name of an organism (or group of organisms).",
        "Clowns are comic performers who employ slapstick or similar types of physical comedy, often in a mime style."
    ],
    [
        "https://en.wikipedia.org/wiki/Clownfish",
        "https://en.wikipedia.org/wiki/Clown"
    ]
]

没有请求。但是,当我从" opensearch"对于别的东西,它确实返回了一个请求ID。

https://en.wikipedia.org/wiki/Special%3aApiSandbox#action=cspreport&format=json&requestid=12

返回:

{
    "error": {
        "code": "cspreport-wrongformat",
        "info": "Error processing CSP report: wrongformat.",
        "*": "See https://en.wikipedia.org/w/api.php for API usage."
    },
    "requestid": "12",
    "servedby": "mw1194"
}

如您所见,此回复确实包含了一个请求。

这是预期的行为,还是我错过了什么?非常感谢任何帮助:)

2 个答案:

答案 0 :(得分:1)

OpenSearch Suggestions extension规范不允许其他返回值,例如requestid。这也是opensearch模块有一个参数将警告视为错误的原因,因为它也不能返回警告。

请尝试使用action=query&list=prefixsearch。这提供了与action = opensearch相同的结果,但是在MediaWiki action API的标准格式中。

答案 1 :(得分:0)

我以前从未使用过MediaWiki API,但是从我刚刚完成的工作开始,opensearch不会返回requestid。我做了https://en.wikipedia.org/w/api.php?requestid=10&action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=jsonfm并返回了


{
    "batchcomplete": "",
    "requestid": "10",
    "query": {
        "pages": {
            "15580374": {
                "pageid": 15580374,
                "ns": 0,
                "title": "Main Page",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "\n{| id=\"mp-topbanner\" style=\"width:100%; background:#f9f9f9; margin:1.2em 0 6px 0; border:1px solid #ddd;\"\n| style=\"width:61%; color:#000;\" |\n\n{| style=\"width:280px; border:none; background:none;\"\n| style=\"width:280px; text-align:center; white-space:nowrap; color:#000;\" |\nWelcome to [[Wikipedia]],\nthe [[free content|free]] [[encyclopedia]] that [[Wikipedia:Introduction|anyone can edit]].\n[[Special:Statistics|{{NUMBEROFARTICLES}}]] articles in [[English language|English]]\n|}\n\n| style=\"width:13%; font-size:95%;\" |\n* [[Portal:Arts|Arts]]\n* [[Portal:Biography|Biography]]\n* [[Portal:Geography|Geography]]\n| style=\"width:13%; font-size:95%;\" |\n* [[Portal:History|History]]\n* [[Portal:Mathematics|Mathematics]]\n* [[Portal:Science|Science]]\n| style=\"width:13%; font-size:95%;\" |\n* [[Portal:Society|Society]]\n* [[Portal:Technology|Technology]]\n* '''[[Portal:Contents/Portals|All portals]]'''\n|}\n\n{{#if:{{Main Page banner}}|\n\n{{Main Page banner}}\n\n\n}}\n\n{| id=\"mp-upper\" style=\"width: 100%; margin:4px 0 0 0; background:none; border-spacing: 0px;\"\n\n| class=\"MainPageBG\" style=\"width:55%; border:1px solid #cef2e0; background:#f5fffa; vertical-align:top; color:#000;\" |\n{| id=\"mp-left\" style=\"width:100%; vertical-align:top; background:#f5fffa;\"\n| style=\"padding:2px;\" | {{#ifexpr:{{formatnum:{{PAGESIZE:Wikipedia:Today's featured article/{{#time:F j, Y}}}}|R}}>150|From today's featured article|Featured article (Check back later for today's.)}}\n|-\n| style=\"color:#000;\" | {{#ifexpr:{{formatnum:{{PAGESIZE:Wikipedia:Today's featured article/{{#time:F j, Y}}}}|R}}>150|{{Wikipedia:Today's featured article/{{#time:F j, Y}}}}|{{Wikipedia:Today's featured article/{{#time:F j, Y|-1 day}}}}}}\n|-\n| style=\"padding:2px;\" | Did you know...\n|-\n| style=\"color:#000; padding:2px 5px 5px;\" | {{Did you know}}\n|}\n| style=\"border:1px solid transparent;\" |\n\n| class=\"MainPageBG\" style=\"width:45%; border:1px solid #cedff2; background:#f5faff; vertical-align:top;\"|\n{| id=\"mp-right\" style=\"width:100%; vertical-align:top; background:#f5faff;\"\n| style=\"padding:2px;\" | In the news\n|-\n| style=\"color:#000; padding:2px 5px;\" | {{In the news}}\n|-\n| style=\"padding:2px;\" | On this day...\n|-\n| style=\"color:#000; padding:2px 5px 5px;\" | {{Wikipedia:Selected anniversaries/{{#time:F j}}}}\n|}\n|}\n{{#switch:{{CURRENTDAYNAME}}|Monday|Friday=\n\n\n\n\n\nFrom today's featured list\n\n{{#ifexist:Wikipedia:Today's featured list/{{#time:F j, Y}}|{{Wikipedia:Today's featured list/{{#time:F j, Y}}}}|{{TFLempty}}}}\n\n\n\n\n|}}\n\n{| id=\"mp-lower\" style=\"margin:4px 0 0 0; width:100%; background:none; border-spacing: 0px;\"\n| class=\"MainPageBG\" style=\"width:100%; border:1px solid #ddcef2; background:#faf5ff; vertical-align:top; color:#000;\" |\n{| id=\"mp-bottom\" style=\"width:100%; vertical-align:top; background:#faf5ff; color:#000;\"\n| style=\"padding:2px;\" | {{#ifexist:Template:POTD protected/{{#time:Y-m-d}}|Today's featured picture | Featured picture (Check back later for today's.)}}\n|-\n| style=\"color:#000; padding:2px;\" | {{#ifexist:Template:POTD protected/{{#time:Y-m-d}}|{{POTD protected/{{#time:Y-m-d}}}}|{{POTD protected/{{#time:Y-m-d|-1 day}}}}}}\n|}\n|}\n\n\n== Other areas of Wikipedia ==\n{{Other areas of Wikipedia}}\n\n== Wikipedia's sister projects ==\n{{Wikipedia's sister projects}}\n\n== Wikipedia languages ==\n{{Wikipedia languages}}\n\n\n{{Main Page interwikis}}{{noexternallanglinks}}{{#if:{{Wikipedia:Main_Page/Tomorrow}}||}}__NOTOC____NOEDITSECTION__"
                    }
                ]
            }
        }
    }
}

如您所见,这有一个请求。我认为MediaWiki不支持在所有操作中使用requestid。

根据我的实验,这是预期的行为。