Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
kullfar merged 1 commit intoscribejava:masterfromlucaswerkmeister:mediawiki
May 23, 2018
Merged

Conversation

lucaswerkmeister
Copy link
Contributor

@lucaswerkmeisterlucaswerkmeister commentedMay 17, 2018
edited
Loading

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.

Daniel-Mietchen, wetneb, nicolas-raoul, JonasKress, and afkbrb reacted with thumbs up emoji
@kullfar
Copy link
Member

How can I test it? Can you provide test app credentials and test user credentials to run the example?

@lucaswerkmeister
Copy link
ContributorAuthor

lucaswerkmeister commentedMay 18, 2018
edited
Loading

You can either request a consumer on meta.wikimedia.org (using the URL in thewikimediaInstance javadoc;there is nothing wrong with creating test consumers), or request a consumer onbeta meta instead (slightly better for test purposes, I think), and adjust the two URLs accordingly.

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
@lucaswerkmeister
Copy link
ContributorAuthor

PR updated, please usewikimediaBetaInstance for testing.

@lucaswerkmeister
Copy link
ContributorAuthor

For the actual authorized request, you could for instance retrieve your watchlist:

https://meta.wikimedia.beta.wmflabs.org/w/api.php?action=query&list=watchlist&format=json

For this, you will need to request the “view your watchlist” grant during registration.

@kullfar
Copy link
Member

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-

@lucaswerkmeister
Copy link
ContributorAuthor

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:

  • Name:ScribeJava test
  • Description:Test consumer for https://github.com/scribejava/scribejava/pull/852
  • OAuth "callback" URL:http://localhost/
  • Applicable grants: check “view your watchlist”
  • check “by submitting this application, you acknowledge…” at the bottom
  • leave everything else at the default

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 noerror in there, it should have worked.

@kullfar
Copy link
Member

Ok, thanks, I'll try to make what I need to.

But

and I don’t think the terms of use would allow me to operate your account for you. Sorry.

it's not my account to be honest, right? ;-)

lucaswerkmeister reacted with heart emoji

@lucaswerkmeister
Copy link
ContributorAuthor

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.

@kullfar
Copy link
Member

After logging in, go to this page and request a consumer with the following data:

I couldn't do this. I got

Permission errorYou do not have permission to do that, for the following reason:You must confirm your email address before creating OAuth applications. Please set and validate your email address through your user preferences.

I'm not going to confirm my email, sorry.

I suppose I could’ve created a little-privileged consumer for my own account and given you the OAuth credentials for that.

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.

@lucaswerkmeister
Copy link
ContributorAuthor

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.

@kullfarkullfar merged commit60d37fe intoscribejava:masterMay 23, 2018
@lucaswerkmeisterlucaswerkmeister deleted the mediawiki branchMay 23, 2018 09:16
@kullfar
Copy link
Member

I have merged the PullRequest to the master with some small changes. Thanks!

@manimaran96
Copy link

System.out.println("And paste the verifier here");
System.out.print(">>");
final String oauthVerifier = in.nextLine();

@kullfar
Here, oauthVerifier value what?
How do I get?

Thanks

@kullfar
Copy link
Member

@manimaran96

        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(">>");        final String oauthVerifier = in.nextLine();

You will get it in your browser. In the URL (most likely) or somehow shown on the screen.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@lucaswerkmeister@kullfar@manimaran96

[8]ページ先頭

©2009-2025 Movatter.jp