php - Validate twitter usename using twitter api version-1.1 -
i want validate twitter usename. referred link
it returns twitter json array when tried in local (xampp) server. returns empty in server.
fyi: curl enabled in server.
how solve this.
updates:
protected function buildbasestring($baseuri, $method, $params) { $r = array(); ksort($params); foreach($params $key => $value){ $r[] = "$key=" . rawurlencode($value); } return $method."&" . rawurlencode($baseuri) . '&' . rawurlencode(implode('&', $r)); } protected function buildauthorizationheader($oauth) { $r = 'authorization: oauth '; $values = array(); foreach($oauth $key=>$value) $values[] = "$key=\"" . rawurlencode($value) . "\""; $r .= implode(', ', $values); return $r; } public function returntweet(){ $oauth_access_token = "mytoken"; $oauth_access_token_secret = "mysecrekkey"; $consumer_key = "my consumer key"; $consumer_secret = "my consumer secret key"; $twitter_timeline = "user_timeline"; $twusername = 'myusername'; // create request $request = array( 'screen_name' => $twusername, 'count' => '3' ); $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' ); $oauth = array_merge($oauth, $request); $base_info = mage::getmodel('namespace/filename')->buildbasestring("https://api.twitter.com/1.1/statuses/$twitter_timeline.json", 'get', $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; $header = array(mage::getmodel('socialtabs/socialtab')->buildauthorizationheader($oauth), 'expect:'); $options = array( curlopt_httpheader => $header, curlopt_header => false, curlopt_url => "https://api.twitter.com/1.1/statuses/$twitter_timeline.json?". http_build_query($request), curlopt_returntransfer => true, curlopt_ssl_verifypeer => false); $feed = curl_init(); curl_setopt_array($feed, $options); $json = curl_exec($feed); curl_close($feed); return $json; }
Comments
Post a Comment