Created
December 29, 2013 06:49
-
-
Save hinaloe/8168099 to your computer and use it in GitHub Desktop.
Croudiaで始めるAPI入門 ref: http://qiita.com/kimama1997/items/e920e8c4f826e493fd7b
This file contains 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
<? | |
//セッションの開始 | |
session_start(); | |
require_once "croudia4php.php"; | |
require_once "config.php"; | |
//code パラメータがあるかどうかをチェック | |
if (!isset($_GET["code"])){ | |
die("Error: No code"); | |
} | |
//Croudia4PHPオブジェクトの生成 | |
$c4p = new Croudia4PHP($ck,$cs); | |
//AccessTokenを取得してセット | |
$c4p -> getAccessToken($_GET["code"]); | |
//SESSIONに認証情報を保存 | |
$_SESSION["c4p"] = serialize($c4p); | |
//とりあえずトークンを画面に吐いてみる。 | |
var_dump($c4p); | |
This file contains 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
<? | |
$ck = "YOUR_CONSUMER_KEY"; | |
$cs = "YOUR_CONSUMER_SECRET"; |
This file contains 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
<? | |
require_once "croudia4php.php"; | |
require_once "config.php"; | |
//Croudia4PHPオブジェクトを生成します. | |
$c4p = new Croudia4PHP($ck,$cs); | |
//認証用のURLを取得します. | |
$url = $c4p -> getAuthorizeURL(); | |
//認証ページへリダイレクト | |
header("Location: $url"); |
This file contains 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
<? | |
//セッション開始 | |
session_start(); | |
//ライブラリinclude | |
require_once "croudia4php.php"; | |
//$c4pオブジェクトを展開 | |
$c4p = unserialize($_SESSION["c4p"]); | |
//パラメーターは配列で指定。 | |
$par = ( | |
"status" => "てすとささやき。", | |
); | |
//APIを叩く | |
$status = $c4p->POST_statuses_update($par); | |
//ささやいたstatusの詳細 | |
echo "<pre>"; | |
var_dump($status); |
This file contains 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
<? | |
//セッション開始 | |
session_start(); | |
//ライブラリinclude | |
require_once "croudia4php.php"; | |
//$c4pオブジェクトを展開 | |
$c4p = unserialize($_SESSION["c4p"]); | |
//パラメーターは配列で指定。 | |
$par = ( | |
"count" => 100, | |
); | |
//APIを叩く。返り値はレスポンスをC4Pがjson_decodeして返してくれる。 | |
$pub = $c4p -> GET_statuses_public_timeline ($par); | |
//とりあえずHTTPヘッダー | |
header("Content-type: text/html; charset=UTF-8"); | |
//$pubは配列で返ってくるのでforeachで順番に吐いてみる。実際に使うときは配列チェックすること。 | |
foreach($pub as $st){ | |
echo $st->user->name . " says : ".$st->text."<br>\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment