ComposerでTwitterOAuthをインストール
PHPでの勉強が進んできたので以前から気になっていたTwitterの操作に挑戦してみる。(成功するまで記事を公開しない)
Twitterをプログラミングで操作する開発を行うにはまずTwitter REST APIについての知識体系を理解する必要がある。
ただし、ライブラリを利用することができればその理解が比較的少なく済む。
いわゆる、”学習コストの削減”というやつだ。
Twitterに関してのライブラリはいくつかあるようだが、特にメジャーなのは「TwitterOAuth」らしい。
なので今回はTwitterOAuthの知識はひとまず、ライブラリを導入(インストール)する手順を残しておく。
ライブラリのインストールにはComposerを使う。
TwitterOAuthをComposerでインストールする
任意のフォルダを用意してそこに移動してから始める。
僕はMAMPを使ってるのでMAMP/htdocs/ここにtwitterフォルダを作成した。
$ cd /Applications/MAMP/htdocs/twitter
つぎにcomposer.jsonファイルを作成する。
initコマンドを打ったら面倒なので全部Enter.
(~~~は名前, ~~~@~~はemailアドレス)
$ composer init
Welcome to the Composer config generator
This command will guide you through creating your composer.json config.
Package name (<vendor>/<name>) [~~~/~~~]:
Description []:
Author [atsuaa <~~~@~~>, n to skip]:
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": "~~~/~~~",
"authors": [
{
"name": "atsuaa",
"email": "~~~@~~"
}
],
"require": {}
}
Do you confirm generation [yes]?
packagistで探してきた名前をrequireする。
Packagist: https://packagist.org/
TwitterOAuthを検索したら「abraham/twitteroauth」だった。
$ composer require abraham/twitteroauth
Using version ^1.1 for abraham/twitteroauth
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing abraham/twitteroauth (1.1.0): Downloading (100%)
Writing lock file
Generating autoload files
$ ls
composer.json composer.lock vendor
composerセットたちが作成されていた。
これでひとまずTwitterOAuthを使うライブラリのインストールは終了!
次は実戦に取り掛かる。
to be continued…
ディスカッション
コメント一覧
まだ、コメントがありません