You are here

public function TwitterProfile::checkConnection in Twitter Profile Widget 8

Same name and namespace in other branches
  1. 8.2 src/TwitterProfile.php \Drupal\twitter_profile_widget\TwitterProfile::checkConnection()

Helper query to check whether the credentials are valid.

Parameters

string $key: Twitter API key.

string $secret: Twitter API secret.

Return value

bool|string Whether or not the connection is valid. If error message, return that.

Overrides TwitterProfileInterface::checkConnection

File

src/TwitterProfile.php, line 165

Class

TwitterProfile
Class TwitterProfile.

Namespace

Drupal\twitter_profile_widget

Code

public function checkConnection($key = '', $secret = '') {
  if ($key == '' || $secret == '') {
    return FALSE;
  }
  $url = 'https://api.twitter.com/1.1/help/tos.json';
  $getfield = '';
  $requestMethod = 'GET';
  $twitter = new TwitterAPIExchange($this
    ->getConnection($key, $secret));
  $data = $twitter
    ->setGetfield($getfield)
    ->buildOauth($url, $requestMethod)
    ->performRequest();
  $result = json_decode($data);
  if (empty($result)) {
    return FALSE;
  }
  elseif (isset($result->errors)) {
    return $result->errors[0]->message;
  }
  return TRUE;
}