<?php
require 'vendor/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
use GuzzleHttp\Client;
// Hata raporlamayı etkinleştir
error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', 1);
// Twitter API anahtarları
$consumerKey = 'api girelecek yer';
$consumerSecret = 'api girelecek yer';
$accessToken = 'api girelecek yer';
$accessTokenSecret = 'api girelecek yer';
// RSS URL'si
$rssUrl = "https://www.aspor.com.tr/rss";
$lastPostedFile = 'last_posted.txt';
$client = new Client(['verify' => false]); // HTTPS sertifikası kontrolünü devre dışı bırak (güvenli değil, sadece test için)
$response = $client->get($rssUrl);
$xml = simplexml_load_string($response->getBody()->getContents());
$entry = $xml->channel->item[0];
$link = (string)$entry->link;
$title = (string)$entry->title;
// Son paylaşılan haberi kontrol et
if (file_exists($lastPostedFile)) {
$lastPosted = file_get_contents($lastPostedFile);
if ($lastPosted === $link) {
exit("Zaten paylaşıldı: $title\n");
}
}
try {
// Twitter'da paylaş
$twitter = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$status = $title . ' ' . $link;
$result = $twitter->post('statuses/update', ['status' => $status]);
if ($twitter->getLastHttpCode() == 200) {
echo "Başarıyla paylaşıldı: $title\n";
file_put_contents($lastPostedFile, $link);
} else {
echo "Paylaşım başarısız oldu.\n";
print_r($result); // API yanıtını yazdır
}
} catch (Exception $e) {
echo "Hata: " . $e->getMessage() . "\n";
}