2016-12-30 3 views
0

Ich versuche, mehrere Ajax Anfragen an Wikipedia zu machen. Die Ajax-Aufrufe befinden sich in einer For-Schleife (JavaScript), was ein Problem darstellt, da sie nicht in der richtigen Reihenfolge zurückgegeben werden. Um dies zu umgehen, dachte ich, ich würde eine Anfrage-ID in die Ajax-Anfrage aufnehmen, wie es eine Option in ihrer Sandbox ist. Problem ist, dass die ID nicht zurückkommt ...?Wikipedia API gibt keine Anfrage ID

(Von Wikimedia sandbox)

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

kehrt:

[ 
    "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" 
    ] 
] 

Kein RequestID. Aber wenn ich die Aktion von "opensearch" zu etwas anderem ändere, gibt es eine Anforderungs-ID zurück.

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

kehrt:

{ 
    "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" 
} 

Wie Sie sehen können, ist diese Reaktion eine RequestID umfassen.

Ist das erwartete Verhalten, oder fehlt mir etwas? Jede Hilfe wird sehr geschätzt :)

+0

Ich habe Probleme, die Dokumentation des 'requestid' Parameters in der API Dokumentation zu finden. Hast du einen Link zu der Seite, die es beschreibt? – Barmar

+0

Es tut mir leid, aber ich habe keine andere Dokumentation als das, was es in der Sandbox (Link in Frage) sagt, wo es heißt: "Jeder hier angegebene Wert wird in der Antwort enthalten sein. Kann verwendet werden, um Anfragen zu unterscheiden. ". Ich verstehe einfach nicht, warum es nicht in einer offenen Suche enthalten sein sollte? Irgendwelche Ideen? – user2267097

+0

Sehr grundsätzlich erklärt [hier] (https://www.mediawiki.org/wiki/API:Main_module) auch, wo es heißt: "requestid: Jeder hier angegebene Wert wird in der Antwort enthalten sein. Kann verwendet werden, um Anfragen zu unterscheiden 1.14+ " – user2267097

Antwort

0

Ich habe noch nie MediaWiki API verwendet, aber von dem, was ich gerade getan habe, liefert opensearch nicht requestid zurück. Ich habe https://en.wikipedia.org/w/api.php?requestid=10&action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=jsonfm und es kehrte


{ 
    "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__" 
        } 
       ] 
      } 
     } 
    } 
} 

Wie Sie sehen können, dass ein RequestID hat. Ich denke, dass MediaWiki keine requestid für alle Aktionen unterstützt.

Aus was ich experimentiert habe, ist dies erwartetes Verhalten.

+0

Diese Antwort wiederholt einfach, was es in der Frage sagt. – Barmar

1

Die OpenSearch Suggestions extension Spezifikation erlaubt keine zusätzlichen Rückgabewerte wie die Anfrage-ID. Aus diesem Grund verfügt das opensearch-Modul über einen Parameter, um Warnungen als Fehler zu behandeln, da es auch keine Warnungen ausgeben kann.

Verwenden Sie stattdessen action=query&list=prefixsearch. Das ergibt die gleichen Ergebnisse wie action = opensearch, aber im Standardformat der MediaWiki Action API.