Cara Memasang Tweet Longer Kanvaso - Faiz Mubarak

Latest

Iseng - iseng ngeBlog [Tempat berbagi tempat bercerita]

Monday, 29 August 2011

Cara Memasang Tweet Longer Kanvaso

1 . Add following line into config.php file of dabr

*/
define('KANVASO_API_KEY', '825614a57c2f13bf449d7779a3f40800461fc080');


/*
* 2. Insert following lines to twitter_update() function in /common/twitter.php
* at line 799 after:
* "$status = twitter_url_shorten(stripslashes(trim($_POST['status'])));"
*/

// shrink the status if it exceeds Twitter's limit 140
if(mb_strlen($status, 'utf-8') > 140)
$status = handle_long_tweet($status);


/*
* 3. Finally, at the end of the /common/twitter.php, copy and paste following function
*/
function handle_long_tweet($status) {
require_once('OAuth.php');

$header = array(
'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json',
'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/"'
);
$consumer = new OAuthConsumer(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
$sha1_method = new OAuthSignatureMethod_HMAC_SHA1();

// user's token
list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']);
$token = new OAuthConsumer($oauth_token, $oauth_token_secret);

// Generate all the OAuth parameters needed
$signingURL = 'https://api.twitter.com/1/account/verify_credentials.json';
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $signingURL, array());
$request->sign_request($sha1_method, $consumer, $token);

$header[1] .= ", oauth_consumer_key=\"" . $request->get_parameter('oauth_consumer_key') . "\"";
$header[1] .= ", oauth_signature_method=\"" . $request->get_parameter('oauth_signature_method') ."\"";
$header[1] .= ", oauth_token=\"" . $request->get_parameter('oauth_token') ."\"";
$header[1] .= ", oauth_timestamp=\"" . $request->get_parameter('oauth_timestamp') ."\"";
$header[1] .= ", oauth_nonce=\"" . $request->get_parameter('oauth_nonce') ."\"";
$header[1] .= ", oauth_version=\"" . $request->get_parameter('oauth_version') ."\"";
$header[1] .= ", oauth_signature=\"" . urlencode($request->get_parameter('oauth_signature')) ."\"";

$url = 'http://api.kanvaso.com/1/update.php';

$ch = curl_init();

$contents = array('text'=>urlencode($status),
'api_key'=>KANVASO_API_KEY,
'format'=>'json');

foreach($contents as $key=>$value) {
$fields .= $key . '=' . $value . '&';
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

$respond = curl_exec($ch);

$response_info = curl_getinfo($ch);

curl_close($ch);

$result = json_decode($respond);
if($result->status == 'success')
return $result->text;
else
return $result->text;
}

Do not forget to visit & use Twitter Client from us at the address www.imorv.com :)

@fays_lee

No comments:

Post a Comment