Jump to content

API:Feedrecentchanges/Sample code 1

From mediawiki.org

Python[edit]

#!/usr/bin/python3

"""
    get_feed_recent_changes.py

    MediaWiki API Demos
    Demo of `Feedrecentchanges` module: Show recent changes as an RSS feed.

    MIT License
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "feedrecentchanges",
    "format": "json"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.content

print(DATA)

PHP[edit]

<?php
/*
    get_feed_recent_changes.php

    MediaWiki API Demos
    Demo of `Feedrecentchanges` module: Show recent changes as an RSS feed.

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "feedrecentchanges",
    "format" => "json"
];

$url = $endPoint . "?" . http_build_query( $params );

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );

var_dump( $output );

JavaScript[edit]

/*
    get_feed_recent_changes.js

    MediaWiki API Demos
    Demo of `Feedrecentchanges` module: Show recent changes as an RSS feed.

    MIT License
*/

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "feedrecentchanges",
    format: "json"
};

url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});

fetch(url)
    .then(function(response){return response.json();})
    .then(function(response) {console.log(response);})
    .catch(function(error){console.log(error);});

MediaWiki JS[edit]

/*
	get_feed_recent_changes.js

	MediaWiki API Demos
	Demo of `Feedrecentchanges` module: Show recent changes as an RSS feed.

	MIT License
*/

var params = {
		action: 'feedrecentchanges',
		format: 'json'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	console.log( data );
} );