public function TwitterAPIExchange::performRequest in Twitter Profile Widget 8
Same name and namespace in other branches
- 8.2 src/Resources/j7mbo/twitter_api_php/TwitterAPIExchange.php \Drupal\twitter_profile_widget\Resources\j7mbo\twitter_api_php\TwitterAPIExchange::performRequest()
Perform the actual data retrieval from the API
Parameters
boolean $return If true, returns data. This is left in for backward compatibility reasons:
array $curlOptions Additional Curl options for this request:
Return value
string json If $return param is true, returns json data.
Throws
\Exception
File
- src/
Resources/ j7mbo/ twitter_api_php/ TwitterAPIExchange.php, line 275
Class
- TwitterAPIExchange
- Twitter-API-PHP : Simple PHP wrapper for the v1.1 API
Namespace
Drupal\twitter_profile_widget\Resources\j7mbo\twitter_api_phpCode
public function performRequest($return = true, $curlOptions = []) {
if (!is_bool($return)) {
throw new Exception('performRequest parameter must be true or false');
}
$header = [
$this
->buildAuthorizationHeader($this->oauth),
'Expect:',
];
$getfield = $this
->getGetfield();
$postfields = $this
->getPostfields();
$options = [
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
] + $curlOptions;
if (!is_null($postfields)) {
$options[CURLOPT_POSTFIELDS] = http_build_query($postfields);
}
else {
if ($getfield !== '') {
$options[CURLOPT_URL] .= $getfield;
}
}
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
$this->httpStatusCode = curl_getinfo($feed, CURLINFO_HTTP_CODE);
if (($error = curl_error($feed)) !== '') {
curl_close($feed);
throw new \Exception($error);
}
curl_close($feed);
return $json;
}