Wikidata:REST API/Authentication/ja

This page is a translated version of the page Wikidata:REST API/Authentication and the translation is 9% complete.

概要

Here’s a quick overview of what you need to know to get authenticated and authorized when using the Wikibase REST API on Wikidata:

  • Set up OAuth 2.0 for your API access on meta.wikimedia.org, Wikimedia's central OAuth service
  • Use your new credentials to start using the API
  • Learn how to properly interact with the Wikibase REST API when authenticated

始める前に

This document was written with Wikidata in mind. The base URL in all examples is https://www.wikidata.org/w/rest.php/wikibase/v0. If you're using your own Wikibase, you need only replace https://wikidata.org with your own site's URL.

See the main document on the REST API for information on error states and rate limiting.

User agent

Requests made against the Wikibase REST API must contain a user agent as per the user-agent policy for Wikimedia sites. If your request lacks a user agent, you will see the following error:

{"code":"missing-user-agent","message":"Request must include User-Agent header","httpCode":400,"httpReason":"Bad Request"}

Setting up OAuth 2.0

To make authenticated requests against the Wikibase REST API for Wikidata, you must first set up an OAuth 2.0 client (formerly known as "consumer").

 
 
  1. Log into meta.wikimedia.org using your unified login.
  2. Create an OAuth 2.0 client.
    (Get there by clicking on Special pages, then OAuth consumer registration, then Request a token for a new consumer.)
  3. Supply the following information to the form:
    Application name: Name it something informative. Example: "Wikibase REST API for Wikidata"
    Application description: Again, use some informative text that explains how you intend to use the API. Example: "Wikibase REST API access for maintaining my dataset about animal cookies"
    This consumer is for use only by (your name) (checkbox): Check this box under normal circumstances. See below for situations when you would leave this box unchecked.
    Applicable grants (checkboxes): Check each box that describes a kind of access you need for your task.
    By submitting this application... (checkbox): Read the user agreement and, if you agree to the terms, check the box.
  4. Submit the form by clicking the "Propose consumer" button.
  5. Save the three tokens provided on the next screen:
    Client application key: used to obtain bearer tokens
    Client application secret: used to obtain bearer tokens
    Access token: provides access to the API when included in the API request (length: ~1800 characters)


Using your credentials

Once you have an access token, you can immediately begin making authenticated requests to the Wikibase REST API.

curl --request GET \
  --url https://www.wikidata.org/w/rest.php/wikibase/v0/entities/items/Q42/statements \
  --header 'Content-Type: application/json' \ 
  --header 'Authorization: Bearer (your access token)'

Non-owner-only clients

If you choose to create an OAuth 2.0 client (consumer) that is not limited to your own use, you will need to refresh your bearer token every four hours using your client application ID and client application secret:

curl --request POST \
  --url https://www.wikidata.org/w/rest.php/oauth2/access_token \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data grant_type=client_credentials \
  --data client_id=(your client id) \
  --data client_secret=(your client secret)

関連項目