Created
June 6, 2014 03:44
-
-
Save memememomo/746caf772bc3fda3fd10 to your computer and use it in GitHub Desktop.
FuelPHPで他のサービスのWebAPIを利用する ref: http://qiita.com/uchiko/items/3cec115db0b99a25d089
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ php oil refine test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Fuel\Tasks; | |
class Test | |
{ | |
public function run() | |
{ | |
// APIのトークン | |
$token = ''; | |
// Request_Curlを生成 | |
// http://fuelphp.jp/docs/1.7/classes/request/curl.html | |
$curl = \Request::forge('https://slack.com/api/users.list', 'curl'); | |
// HTTPメソッドを指定 | |
$curl->set_method('post'); | |
// パラメータを設定 | |
$curl->set_params(array('token' => $token)); | |
// 実行 | |
// $responseには、Responseインスタンスが入る | |
// http://fuelphp.jp/docs/1.7/classes/response.html | |
$response = $curl->execute()->response(); | |
// レスポンスコードチェック | |
if ($response->status == 200) | |
{ | |
// Formatクラスを利用して、JSONからPHPの配列に変換 | |
// http://fuelphp.com/docs/classes/format.html | |
$data = \Format::forge($response->body,'json')->to_array(); | |
// 中身をチェック | |
var_dump($data); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment