28 Kasım 2014 · Yazılım · 1 dk okuma
Twitter API – Trend topiclere otomatik tweet attırma
Bu yazı 2014 tarihli ve arşivde. İçindeki kod ve servisler bugün çalışmayabilir.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twitter Send Tweet</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
</head>
<body>
<?php
/**
* Twitter API
* @author Selim Hallaç
* x.com/selimhallac
*/
/**
* Twitter API File
* Twitter API Dosyası
*/
include "twitteroauth/twitteroauth.php";
/**
* Twitter API Config
* Twitter API için gerekli bağlantı bilgileri
*/
$consumer_key = '';
$consumer_secret = '';
$accesstoken = '';
$accesstokensecret = '';
/**
* Twitter API Connections
* Twitter API ile bağlantı
* @var TwitterOAuth
*/
$twitter = new TwitterOAuth($consumer_key, $consumer_secret, $accesstoken, $accesstokensecret);
$placecode = '23424969'; // Bölge kodu, yahodan bulabilirsin ben şuan Türkiye için koydum
$trendlist = $twitter->get('https://api.twitter.com/1.1/trends/place.json?id='.$placecode);
echo "<pre>";
print_r($trendlist);
echo "</pre>";
foreach ($trendlist['0']->trends as $key => $value) {
$tweet['status'] = $value->name." ".rand(0,150); # Tweet Attırma.
$twitter->post('statuses/update',$tweet);
}
?>
<pre>
</pre>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
</body>
</html>