GithubHelp home page GithubHelp logo

yetanotherwikidataapi's Introduction

This project exposes the Wikidata API as a Kotlin library.

Wikidata API

For testing, get yourself an API token:

  1. Go to https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration/propose/oauth2 to request yourself an API token
  2. Mark the client as confidential
  3. Mark it as consumer use for yourself only and the token is auto-accepted for 30 days.
  4. Request specific permissions, but only the basic rights is enough.
  5. Submit the proposal, get Client application key, Client application secret, and Access token

Now you may try the API with this library, or manually:

  1. Go to https://doc.wikimedia.org/Wikibase/master/js/rest-api/ to find examples of all the API calls
  2. Note that the page has an invalid "example" server configured to it -- use https://www.wikidata.org/w/rest.php/wikibase/v0 instead, like this:
curl -X 'GET' \
   'https://www.wikidata.org/w/rest.php/wikibase/v0/entities/items/Q42' \
   -H 'accept: application/json' \
   -H 'Authorization: Bearer YOUR_ACCESS_TOKEN_GOES_HERE'

Using this library

If you work with Maven, add a new repository into your ~/.m2/settings.xml file:

<repository>
   <id>github</id>
   <url>https://maven.pkg.github.com/ZeroOne3010/yetanotherwikidataapi</url>
   <!--snapshots>
     <enabled>true</enabled>
   </snapshots-->
</repository>

Also add username and access token for GitHub Packages:

<servers>
   <server>
      <id>github</id>
      <username>YOUR_GITHUB_USERNAME</username>
      <password>YOUR_GITHUB_TOKEN_WITH_READ_PACKAGES_PRIVILEGE</password>
   </server>
</servers>

Then, in your project's pom.xml, include this artifact:

<dependency>
   <groupId>io.github.zeroone3010</groupId>
   <artifactId>yetanotherwikidataapi</artifactId>
   <version>0.0.1</version>
</dependency>

Now, a minimal code example would look like this:

import io.github.zeroone3010.wikidata.Item;
import io.github.zeroone3010.wikidata.Wikidata;

public class Main {
   public static void main(String[] args) {
      Wikidata wikidata = new Wikidata(args[0]);
      String itemId = "Q1085";
      Item item = wikidata.getItem(itemId);
      System.out.println(itemId + " is " + item.getLabels().get("en"));
   }
}

And it would print out "Q1085 is Prague".

yetanotherwikidataapi's People

Contributors

vsaalo-nitor avatar zeroone3010 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.