0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravalで楽天商品APIを使うときの覚書

0
Last updated at Posted at 2026-01-07

2026年5月14日以降、楽天APIのドメイン変更と認証システムの変更によりSDKが使用できなくなりました。
本記事ではSDKの導入時に躓いた点や解決方法を記載しているため、他SDKの導入の参考程度に留めてください。

はじめに

楽天商品APIはSDKが配布されており、簡単に実装できると踏んでいたら導入でずっこけたので覚書程度に記録を残しておこうと思います。
当方は初心者エンジニアであり、PHPやLaravelは独学のため拙い部分もございますがご了承ください。

簡単に使用している環境について記載します。

  • PHP8.3
  • Laravel Framework 12.45.1
  • Ubuntu
  • Docker Desktop使用

楽天商品APIのSDKについて

GitHubにて公開されており、基本的な導入方法についてもこちらに記載されています。
https://github.com/rakuten-ws/rws-php-sdk

今回はこちらの導入方法に沿って進めたいと思います。

composerの入手

SDKのREADME.mdには下記のように記載があります。

RWS PHP SDK は、Packagist にパッケージ登録を行っています。 そのため、 Composer を通してパッケージを入手することができます。

ではお言葉に甘えて、まずはcomposerを入手します。
後に発覚いたしますが、当方は既にcomposerをインストールしていたため不要な手順でした。

curl -s http://getcomposer.org/installer | php

上記コマンドを実行すると、
Composer (version 2.9.3) successfully installed to...と表示されたため成功しているようです。
次の手順に進みましょう。

composer.jsonを作成する

手順には下記のように記載がありました。

あなたの開発プロジェクトのルートに composer.json を作成します。

ここで前項の通り 「当方は既にcomposerをインストールしていたため」 が影響します。
既にcomposer.jsonが存在しているのです。
composer.jsonを丸々上書きするのは怖いので、下記のように追記しました

composer.json
~~~~
~~~~
    "require": {
        "rakuten-ws/rws-php-sdk": "1.*",
        (略)
    },
~~~~
~~~~

composerを通してパッケージを入手する

次の手順は下記コマンドを実行することでした。いざ実行!

php composer.phar install

WARNINGが出ている上に上手くインストールされていないようです。

Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.                                                                        
- Required package "rakuten-ws/rws-php-sdk" is not present in the lock file.
This usually happens when composer files are incorrectly merged or the composer.json file is manually edited.
Read more about correctly resolving merge conflicts https://getcomposer.org/doc/articles/resolving-merge-conflicts.md
and prefer using the "require" command over editing the composer.json file directly https://getcomposer.org/doc/03-cli.md#require-r

よくわかりませんが、

  • composer.lockにrakuten-ws/rws-php-sdkが無い
  • これはcomposer.jsonを手動で編集すると発生する
  • 直接編集しないでrequireコマンドを使ってね

というエラーのようでした。

requireコマンドで実行する

ということで言われた通りrequireコマンドを実行してみようと思います。

composer require rakuten-ws/rws-php-sdk

結果

./composer.json has been updated                                                                                                             
Running composer update rakuten-ws/rws-php-sdk
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/pint is locked to version v1.27.0 and an update of this package was not requested.
    - laravel/pint v1.27.0 requires ext-xml * -> it is missing from your system. Install or enable PHP's xml extension.
  Problem 2
    - phpunit/phpunit is locked to version 11.5.46 and an update of this package was not requested.
    - phpunit/phpunit 11.5.46 requires ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
  Problem 3
    - tijsverkoyen/css-to-inline-styles v2.4.0 requires ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.  
    - laravel/framework v12.45.1 requires tijsverkoyen/css-to-inline-styles ^2.2.5 -> satisfiable by tijsverkoyen/css-to-inline-styles[v2.4.0].
    - laravel/framework is locked to version v12.45.1 and an update of this package was not requested.

色々でてきましたがそれぞれ解決してみます。

PHPの拡張機能をインストールする

調べてみたところ、全て必要な拡張機能がインストールされていないというエラーのようです。
今回はext-xmlとext-domが不足しているようなのでインストールします。

まず、パッケージリストを更新。

sudo apt update

その後、拡張機能をインストールします。
下記のコマンドのみでext-domも同時にインストールされるようです。

sudo apt install php-xml

もう一度requireコマンドを実行してみます。

composer require rakuten-ws/rws-php-sdk

上手くいってくれ~~~!!!

./composer.json has been updated
Running composer update rakuten-ws/rws-php-sdk
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - symfony/css-selector v8.0.0 requires php >=8.4 -> your php version (8.3.6) does not satisfy that requirement.
    - laravel/framework v12.45.1 requires tijsverkoyen/css-to-inline-styles ^2.2.5 -> satisfiable by tijsverkoyen/css-to-inline-styles[v2.4.0].
    - tijsverkoyen/css-to-inline-styles v2.4.0 requires symfony/css-selector ^5.4 || ^6.0 || ^7.0 || ^8.0 -> satisfiable by symfony/css-selector[v8.0.0].
    - laravel/framework is locked to version v12.45.1 and an update of this package was not requested.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require rakuten-ws/rws-php-sdk:*" to figure out if any version is installable, or "composer require rakuten-ws/rws-php-sdk:^2.1" if you know which you need.

また別のエラーが発生しました・・・。

symfony/css-selectorで要求されているPHPのバージョンを変更する(非推奨)

symfony/css-selectorでPHP8.4が要求されているようですが、今回はPHP8.3.6を使用しています。
あくまで学習の一環としてコーディングがしたいだけなので、今回はPHP8.3に合わせてもらいます。

業務等で使用する場合は非推奨です。一時的な措置として捉えてください。

symfony/css-selector内のcomposer.jsonを確認してみます。

symfony/css-selector/composer.json
~~~
~~~~
    "require": {
        "php": ">=8.4"
    },
    "autoload": {
        "psr-4": { "Symfony\\Component\\CssSelector\\": "" },
        "exclude-from-classmap": [
            "/Tests/"
        ]
    },
~~~~~
~~~

この部分が該当箇所のようですね。
下記のように書き換えます。

symfony/css-selector/composer.json
~~~
~~~~
    "require": {
        "php": ">=8.3"
    },
    "autoload": {
        "psr-4": { "Symfony\\Component\\CssSelector\\": "" },
        "exclude-from-classmap": [
            "/Tests/"
        ]
    },
~~~~~
~~~

念のためcomposer.lockも書き換えておきます。

composer.lock
~~~
~~~~
            "name": "symfony/css-selector",
            "version": "v7.4.0",
            "source": {
            ~~~~~
            ~~~~~
            },
            "require": {
                "php": ">=8.3"
            },
            "type": "library",
            "autoload": {
~~~~
~~~

composer.json諸々を更新したのでupdateします。

composer update

そして再度requireコマンドを実行。

composer require rakuten-ws/rws-php-sdk

下記の表示が確認できました!
インストールできたようです。

No security vulnerability advisories found.
Using version ^1.1 for rakuten-ws/rws-php-sdk

まとめ

  1. curl -s http://getcomposer.org/installer | phpでcomposerを入手
  2. composer require rakuten-ws/rws-php-sdkでパッケージをインストール
  3. PHPの拡張機能が不足してエラーが発生した場合はsudo apt updateとsudo apt install php-xmlでインストール
  4. エラーが解消されない場合、symfony/css-selectorで指定されているPHPのバージョンを確認する
  5. 使用しているPHPのバージョンが古い場合はPHPのバージョンアップ、
    もしくはsymfony/css-selector/composer.jsonに記載されているPHPのバージョンを変更
  6. composer update後にもう一度composer require rakuten-ws/rws-php-sdkを実行
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?