- Notifications
You must be signed in to change notification settings - Fork1.7k
Add MediaWiki API#852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
8365214
to8a03241
CompareHow can I test it? Can you provide test app credentials and test user credentials to run the example? |
You can either request a consumer on meta.wikimedia.org (using the URL in the Both require a registered Wikimedia account with confirmed email address, but having a Wikimedia account doesn’t hurt anyways, perhaps you can even contribute in the future? ;) Actually, since I learned that beta meta also supports OAuth, I might add a second instance for that to make the tests easier. Hang on… :) |
This API can be used for any MediaWiki installation that has the OAuthextension [1] installed. Two default instances are provided forconvenience: one for wikis hosted by the Wikimedia Foundation (includingWikipedia), which is the one most users will be interested in, and onefor the Wikimedia Foundation’s Beta Cluster, which is more appropriatefor testing purposes.The example is copied and slightly adapted from AWeberExample.java.[1]:https://www.mediawiki.org/wiki/Extension:OAuth
PR updated, please use |
For the actual authorized request, you could for instance retrieve your watchlist:
For this, you will need to request the “view your watchlist” grant during registration. |
Hi, sorry I can't register new account in every network. (c)https://github.com/scribejava/scribejava/wiki/FAQ#when-will-you-support-insert_api_here- |
Alright, I registered an account for you (Kullfar), you should have received the password via email. After logging in, go tothis page and request a consumer with the following data:
Icannot do this for you – I don’t have your password, and I don’t think the terms of use would allow me to operate your account for you. Sorry. Afterwards, you can test the consumer without waiting for the request to be approved, with something like this: importjava.util.Scanner;importcom.github.scribejava.core.builder.ServiceBuilder;importcom.github.scribejava.apis.MediaWikiApi;importcom.github.scribejava.core.model.OAuth1AccessToken;importcom.github.scribejava.core.model.OAuth1RequestToken;importcom.github.scribejava.core.model.OAuthRequest;importcom.github.scribejava.core.model.Response;importcom.github.scribejava.core.model.Verb;importcom.github.scribejava.core.oauth.OAuth10aService;importjava.io.IOException;importjava.util.concurrent.ExecutionException;publicfinalclassMediaWikiExample {privatestaticfinalStringCONSUMER_KEY ="";privatestaticfinalStringCONSUMER_SECRET ="";privatestaticfinalStringAPI_WATCHLIST_URL ="https://meta.wikimedia.beta.wmflabs.org/w/api.php?action=query&list=watchlist&format=json"privateMediaWikiExample() { }publicstaticvoidmain(String...args)throwsIOException,InterruptedException,ExecutionException {finalOAuth10aServiceservice =newServiceBuilder(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) .build(MediaWikiApi.wikimediaInstance());finalScannerin =newScanner(System.in);// Obtain the Request TokenfinalOAuth1RequestTokenrequestToken =service.getRequestToken();System.out.println("Now go and authorize ScribeJava here:");System.out.println(service.getAuthorizationUrl(requestToken));System.out.println("And paste the verifier here");System.out.print(">>");finalStringoauthVerifier =in.nextLine();System.out.println();// Trade the Request Token and Verfier for the Access TokenfinalOAuth1AccessTokenaccessToken =service.getAccessToken(requestToken,oauthVerifier);// Now let's go and ask for a protected resource!finalOAuthRequestrequest =newOAuthRequest(Verb.GET,API_WATCHLIST_URL);service.signRequest(accessToken,request);finalResponseresponse =service.execute(request);System.out.println(response.getBody()); }} The output will probably look like this: {"batchcomplete":"","query": {"watchlist": [] }} As long as there’s no |
Ok, thanks, I'll try to make what I need to. But
it's not my account to be honest, right? ;-) |
Well IMHO it’s certainly not mine, being registered under your name to your email address :) Come to think of it, I suppose I could’ve created a little-privileged consumer for my own account and given you the OAuth credentials for that. Would mean a bit more waiting time (you’d have to send me the authorization URL and then I’d have to send the verifier back to you), but perhaps less effort for you – let me know if you want to go that route instead. |
I couldn't do this. I got
I'm not going to confirm my email, sorry.
Can you just create the new test user. With any your email (maybe new one, fake), register OAuth app and just send me user login/pass and App id/secret/callback? It's the easiest way as I see. |
Hrmpf, you’d think the email could be considered validated already since the password was sent to it… but apparently that’s not implemented yet (T159749). I’ll see what I can do about the test user tonight. |
I have merged the PullRequest to the master with some small changes. Thanks! |
manimaran96 commentedApr 21, 2020
@kullfar Thanks |
You will get it in your browser. In the URL (most likely) or somehow shown on the screen. |
Add MediaWiki API
This API can be used for any MediaWiki installation that has theOAuth extension installed. Two default instances are provided for convenience: one for wikis hosted by the Wikimedia Foundation (including Wikipedia), which is the one most users will be interested in, and one for the Wikimedia Foundation’s Beta Cluster, which is more appropriate for testing purposes.
The example is copied and slightly adapted from AWeberExample.java.