Google Api PHP Client の インストール

スポンサードリンク

Googleが提供しているPHP用のAPIクライアントをComposerを使ってインストールする。

ディレクトリを作成する

[sepg@sv6115 ~]$ mkdir myproject2
[sepg@sv6115 ~]$ cd myproject2

composer.pharをインストールする

[sepg@sv6115 myproject2]$ curl -s https://getcomposer.org/installer | php
[sepg@sv6115 myproject2]$ ll
-rwxr-xr-x 1 sepg members 1861877 4月 8 22:50 composer.phar

initで初期設定

[sepg@sv6115 myproject2]$ php composer.phar init

基本enterでよいかと

  Welcome to the Composer config generator



This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [sepg/myproject2]:
Description []:
Author [, n to skip]: n
Minimum Stability []:
Package Type (e.g. library, project, metapackage, composer-plugin) []:
License []:

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]?
Search for a package:
Would you like to define your dev dependencies (require-dev) interactively [yes]?
Search for a package:

{
    "name": "sepg/myproject2",
    "require": {}
}

Do you confirm generation [yes]?

composer.jsonが出来上がる

[sepg@sv6115 myproject2]$ ll
合計 1824
-rw-r--r-- 1 sepg members      53  4月  9 20:30 composer.json
-rwxr-xr-x 1 sepg members 1861877  4月  8 22:50 composer.phar

requireコマンドでgoogle api clientを入れ込む

[sepg@sv6115 myproject2]$ php composer.phar require google/apiclient:^2.0

インストール中…

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 14 installs, 0 updates, 0 removals
  - Installing psr/http-message (1.0.1): Downloading (100%)
  - Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
  - Installing react/promise (v2.5.1): Downloading (100%)
  - Installing guzzlehttp/streams (3.0.0): Downloading (100%)
  - Installing guzzlehttp/ringphp (1.1.0): Downloading (100%)
  - Installing guzzlehttp/guzzle (5.3.2): Downloading (100%)
  - Installing phpseclib/phpseclib (2.0.10): Downloading (100%)
  - Installing psr/log (1.0.2): Loading from cache
  - Installing monolog/monolog (1.23.0): Downloading (100%)
  - Installing firebase/php-jwt (v5.0.0): Downloading (100%)
  - Installing google/apiclient-services (v0.54): Downloading (100%)
  - Installing psr/cache (1.0.1): Downloading (100%)
  - Installing google/auth (v1.3.0): Downloading (100%)
  - Installing google/apiclient (v2.2.1): Downloading (100%)

完了するとvendor配下にgoogle apiが依存関係を保持しながら配置される

[sepg@sv6115 myproject2]$ ll vendor/
合計 4
-rw-r--r-- 1 sepg members 178  4月  9 20:45 autoload.php
drwxr-xr-x 2 sepg members 269  4月  9 20:45 composer
drwxr-xr-x 3 sepg members  29  4月  9 20:45 firebase
drwxr-xr-x 5 sepg members  77  4月  9 20:45 google
drwxr-xr-x 6 sepg members  82  4月  9 20:45 guzzlehttp
drwxr-xr-x 3 sepg members  29  4月  9 20:45 monolog
drwxr-xr-x 3 sepg members  31  4月  9 20:45 phpseclib
drwxr-xr-x 5 sepg members  66  4月  9 20:45 psr
drwxr-xr-x 3 sepg members  29  4月  9 20:45 react

実際にgoogle apiを使用する場合はvendor配下のautoload.phpをrequreすればOK

<?php
  require 'vendor/autoload.php';
?>

スポンサードリンク

シェアする

  • このエントリーをはてなブックマークに追加

フォローする