Tech

From Meta, a Wikimedia project coordination wiki

Question about using the MediaWiki API to edit pages[edit]

I want to use the MediaWiki API to edit pages. And when:

  • My query parameters include "token" (CSRF token), it told me "The following parameter was found in the query string, but must be in the POST body: token."
  • When I move it to the body of the POST, 'The "token" parameter must be set.'
  • No matter how I use it, it responds with a 301 error.

Is it something wrong with the server? Or my code... The content below is my code(in Dart):

final headers = {
  'User-Agent': 'WikiApp/1.0 contact: [email]',
  'Authorization': 'Bearer $credentials', 
};
final code = await http.post(
  Uri(
      scheme: 'https',
      host: fullServerName,
      path: '${wgScriptPath}api.php',
      queryParameters: {
        'action': 'query',
        'meta': 'tokens',
        'format': 'json',
      }),
);
var data = code.body;
final Map wikiTOC = jsonDecode(data);
String token = wikiTOC['query']['tokens']['csrftoken'];
final apiUrl = Uri(
  scheme: 'https',
  host: wgServer,
  path: '${wgScriptPath}api.php',
  queryParameters: {
    'action': 'edit',
    'format': 'json',
    'title': PageName,
    'summary': 'Edited via MyApp',
    'text': textContent,
    'token': token,
  },);


final response = await http.post(
  apiUrl,
  headers: headers,
);

--Creamycd (talk) 06:44, 17 February 2024 (UTC)[reply]

By the way, the full code has been MITed to GitHub--Creamycd (talk) 08:58, 17 February 2024 (UTC)[reply]

Sorry, wrong place --Creamycd (talk) 09:01, 17 February 2024 (UTC)[reply]

Getting Details Of Videos and Audio From the API[edit]

Dear,

I'm writing to follow up on my API call results. While I was able to successfully retrieve images and descriptions for my search keyword.

API: https://en.wikipedia.org/w/rest.php/v1/search/page?q=World&limit=2

I couldn't locate any information related to audio files & a video files.

Could you please clarify if audio & video files are included in the API response for this particular search? If not, is there another way to access audio & video files related to my search keyword on this platform using Specific API?

Thank you! UsmanKhanLodhi (talk) 07:29, 11 March 2024 (UTC)[reply]