public function TwitterAPIExchange::buildOauth in Heartbeat 8
Build the Oauth object using params set in construct and additionals passed to this method. For v1.1, see: https://dev.twitter.com/docs/api/1.1
Parameters
string $url The API url to use. Example: https://api.twitter.com/1.1/search/tweets.json:
string $requestMethod Either POST or GET:
Return value
\TwitterAPIExchange Instance of self for method chaining
Throws
\Exception
1 call to TwitterAPIExchange::buildOauth()
- TwitterAPIExchange::setPostfields in modules/
statusmessage/ includes/ TwitterAPIExchange.php - Set postfields array, example: array('screen_name' => 'J7mbo')
File
- modules/
statusmessage/ includes/ TwitterAPIExchange.php, line 205
Class
- TwitterAPIExchange
- Twitter-API-PHP : Simple PHP wrapper for the v1.1 API
Code
public function buildOauth($url, $requestMethod) {
if (!in_array(strtolower($requestMethod), array(
'post',
'get',
'put',
'delete',
))) {
throw new Exception('Request method must be either POST, GET or PUT or DELETE');
}
$consumer_key = $this->consumer_key;
$consumer_secret = $this->consumer_secret;
$oauth_access_token = $this->oauth_access_token;
$oauth_access_token_secret = $this->oauth_access_token_secret;
$oauth = array(
'oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0',
);
$getfield = $this
->getGetfield();
if (!is_null($getfield)) {
$getfields = str_replace('?', '', explode('&', $getfield));
foreach ($getfields as $g) {
$split = explode('=', $g);
/** In case a null is passed through **/
if (isset($split[1])) {
$oauth[$split[0]] = urldecode($split[1]);
}
}
}
$postfields = $this
->getPostfields();
if (!is_null($postfields)) {
foreach ($postfields as $key => $value) {
$oauth[$key] = $value;
}
}
$base_info = $this
->buildBaseString($url, $requestMethod, $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
$this->url = $url;
$this->requestMethod = $requestMethod;
$this->oauth = $oauth;
return $this;
}