twitteroauthでAPI制限取得

twitteroauthを使った簡易クラスにAPI制限(rate_limit_status)を追加

アクションコントローラのクラスにprivateメソッドを追加。

PHP

class twitterController { (略) /** * インデックスアクション */ public function indexAction() { $response = $this->applicationRateLimitStatus(); print_r($response); exit; } /** * レート制限 * * @param string $resources * @return array */ private function applicationRateLimitStatus($resources = 'statuses,friends,trends,help') { // url $url = 'application/rate_limit_status'; // リソース $parameters['resources'] = $resources; $response = $this->twitteroauth->get($url, $parameters); if (! empty($response->resources)) { $resource = explode(',', $resources); for ($i = 0; $i < count($resource); $i++) { foreach($response->resources->$resource[$i] as $resourceKey => $resourceVal) { // リセットされる日時 $response->resources->$resource[$i]->$resourceKey->reset_date = date('Y-m-d H:i:s', $resourceVal->reset); // リセットされるまでの残分 $response->resources->$resource[$i]->$resourceKey->rest_minutes = ceil(($resourceVal->reset - strtotime('now')) / 60); } } } return $response; } }

$response

stdClass Object ( [rate_limit_context] => stdClass Object ( [access_token] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ) [resources] => stdClass Object ( [friends] => stdClass Object ( [/friends/ids] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) ) [statuses] => stdClass Object ( [/statuses/home_timeline] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/statuses/mentions_timeline] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/statuses/retweets_of_me] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/statuses/show/:id] => stdClass Object ( [limit] => 180 [remaining] => 180 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/statuses/retweets/:id] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/statuses/user_timeline] => stdClass Object ( [limit] => 180 [remaining] => 180 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/statuses/oembed] => stdClass Object ( [limit] => 180 [remaining] => 180 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) ) [trends] => stdClass Object ( [/trends/available] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/trends/closest] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/trends/place] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) ) [help] => stdClass Object ( [/help/privacy] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/help/tos] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/help/configuration] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) [/help/languages] => stdClass Object ( [limit] => 15 [remaining] => 15 [reset] => 1353510000 [reset_date] => 2012-11-22 00:00:00 [rest_minutes] => 15 ) ) ) )

最新の記事

プロフィール

流されるままにウェブ業界で仕事しています。主にLAPP環境でPHPを書いています。最近はjQueryで遊んでいます。
※動作確認について