You are here

public function TwitterAPIExchange::performRequest in Twitter Profile Widget 8.2

Same name and namespace in other branches
  1. 8 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_php

Code

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);
  $feed = curl_init();
  curl_setopt_array($feed, $options);
  try {
    $json = curl_exec($feed);
    $this->httpStatusCode = curl_getinfo($feed, CURLINFO_HTTP_CODE);
    curl_close($feed);
    return $json;
  } catch (Exception $e) {
    \Drupal::logger('type')
      ->error($e
      ->getMessage());
  }
  return;
}