/** * * @see https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status */ public function getStatus() { // Return the cached response if available. $_sCacheID = FetchTweets_Commons::TransientPrefix . '_' . md5(serialize(array($this->sConsumerKey, $this->sConsumerSecret, $this->sAccessToken, $this->sAccessSecret))); $_vData = FetchTweets_WPUtilities::getTransient($_sCacheID); if (false !== $_vData) { return $_vData; } // Perform the requests. $_oConnect = new FetchTweets_TwitterOAuth($this->sConsumerKey, $this->sConsumerSecret, $this->sAccessToken, $this->sAccessSecret); $_aUser = $_oConnect->get('account/verify_credentials'); // If the user id could not be retrieved, it means it failed. if (!isset($_aUser['id']) || !$_aUser['id']) { return array(); } // Otherwise, it is okay. Retrieve the current status. $_aStatusKeys = apply_filters('fetch_tweets_filter_request_rate_limit_status_keys', array('statuses', 'search', 'lists')); // keys can be added such as 'help', 'users' etc $_aStatus = $_oConnect->get('https://api.twitter.com/1.1/application/rate_limit_status.json?resources=' . implode(',', $_aStatusKeys)); // Set the cache. $_aData = is_array($_aStatus) ? $_aUser + $_aStatus : $_aUser; FetchTweets_WPUtilities::setTransient($_sCacheID, $_aData, 60); // stores the cache only for 60 seconds. return $_aData; }
/** * Checks the API credential is valid or not. * * @since 1.3.0 * @return array the retrieved data. * @remark The returned data is a merged result of 'account/verify_credientials' and 'rate_limit_status'. */ protected function verifyCrediential($strConsumerKey, $strConsumerSecret, $strAccessToken, $strAccessSecret) { // Return the cached response if available. $strCachID = FetchTweets_Commons::TransientPrefix . '_' . md5(serialize(array($strConsumerKey, $strConsumerSecret, $strAccessToken, $strAccessSecret))); $vData = get_transient($strCachID); if ($vData !== false) { return $vData; } // Perform the requests. $oTwitterOAuth = new FetchTweets_TwitterOAuth($strConsumerKey, $strConsumerSecret, $strAccessToken, $strAccessSecret); $arrUser = $oTwitterOAuth->get('account/verify_credentials'); // If the user id could not be retrieved, it means it failed. if (!isset($arrUser['id']) || !$arrUser['id']) { return array(); } // Otherwise, it is okay. Retrieve the current status. $arrStatus = $oTwitterOAuth->get('https://api.twitter.com/1.1/application/rate_limit_status.json?resources=help,users,search,statuses'); // Set the cache. $arrData = is_array($arrStatus) ? $arrUser + $arrStatus : $arrUser; set_transient($strCachID, $arrData, 60 * 2); // stores the cache only for 120 seconds. It is allowed 15 requests in 15 minutes. return $arrData; }