0

I want to validate twitter usename. I referred this Link

It returns the twitter json array when i tried in local (XAMPP) server. But it returns empty in server.

FYI: CURL is enabled in the server.

How to solve this.

Updates:

protected function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
foreach($params as $key => $value){
    $r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); 
}


protected function buildAuthorizationHeader($oauth) {
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $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;
}
Community
  • 1
  • 1
Saravanan DS
  • 278
  • 3
  • 14
  • Can you show us the code you're using? – Terence Eden Jul 30 '16 at 10:53
  • Please check the below link. Same code is used and i tried with regenerating codes and app too. http://stackoverflow.com/questions/12916539/simplest-php-example-for-retrieving-user-timeline-with-twitter-api-version-1-1/34547898#34547898 – Saravanan DS Jul 30 '16 at 13:59
  • It helps if you show us the exact code that *you* are using - and the exact errors you are getting. Why have you chosen that specific solution when there are much better ones on that page? – Terence Eden Jul 30 '16 at 17:14
  • Hi, @Terence I have updated my question with my actual codes am using. Am using this in my magento E-Commerce site. I have tried with some other solutions. But, I caught solution from this one. So only i used this code. Please check and suggest me some other working examples. I'll check with that one. – Saravanan DS Aug 01 '16 at 07:23

0 Answers0