Skip to content

Instantly share code, notes, and snippets.

@karmiphuc
Created September 24, 2013 08:44
Show Gist options
  • Save karmiphuc/6682033 to your computer and use it in GitHub Desktop.
Save karmiphuc/6682033 to your computer and use it in GitHub Desktop.
Twitter Flow
function getProfileInBulks($bulkID, $attr = 'profile_image_url') {
$opt = $this->options;
$consumer_key = $opt['c_k'];
$consumer_sec = $opt['c_s'];
$oauth_access_token = $opt['o_a_t'];
$oauth_access_sec = $opt['o_a_s'];
$url = 'https://api.twitter.com/1.1/users/lookup.json';
$this->updateUrl($url);
$oauth = $this->buildOauthArray($consumer_key, $oauth_access_token);
$this->resetParams();
$this->appendParams($bulkID, 'screen_name');
$this->appendParams('false', 'include_entities');
$oauth = array_merge($oauth, $this->paramsArr);
$requestType = 'POST';
$queryUrl = $this->params?$this->searchURL.'?'.$this->params:$this->searchURL;
$base_info = $this->buildBaseString($this->searchURL, $requestType, $oauth);
$composite_key = rawurlencode($consumer_sec) . '&' . rawurlencode($oauth_access_sec);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
unset($oauth['screen_name']);
unset($oauth['include_entities']);
$oauth['oauth_signature'] = $oauth_signature;
uksort($oauth, 'strcmp');
$header = array($this->buildAuthorizationHeader($oauth));
$resp = $this->curlConnect($queryUrl, $header, $requestType, $this->paramsArr);
$users = json_decode($resp, TRUE);
if (count($users)) {
switch ($attr) {
case 'profile_image_url':
$rtn = array();
foreach ($users as $user) {
$_name = $user['screen_name'];
$rtn[$_name] = $user[$attr];
}
return $rtn;
default:
return 0;
}
} else return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment