function tweetidCheck($id, $admin)
{
if (is_numeric($id)) {
$yasakli = 0;
$data = file("../token.txt");
shuffle($data);
$data = array_reverse($data);
$token = $data[0];
$token = json_decode($token);
$opt = array("api_url" => "https://api.twitter.com/1.1/statuses/show.json", "consumer_key" => "3nVuSoBZnx6U4vzUxf5w", "consumer_secret" => "Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys", "access_token" => $token->access_token, "access_token_secret" => $token->access_token_secret, "method" => "GET", "post" => array("id" => $id), "header" => true);
$que = curl_api($opt);
if ($que->http_code != 0) {
$decode = json_decode($que->content);
$hataSorgu = isset($decode->errors) ? $decode->errors : 0;
$hata_Sorgu = isset($decode->error) ? $decode->error : 0;
if ($hataSorgu != 0 || $hata_Sorgu != 0) {
$json = array("error" => true, "mesaj" => "Bilinmeyen bir hata oluştu. Hesabınızın korumalı olup olmadığını kontrol ettikten sonra tekrar deneyin.");
} else {
$decod = json_decode($que->content);
if ($admin != 1 && sansurKelime) {
$bolBakalim = explode(",", sansurKelime);
foreach ($bolBakalim as $kelime) {
if (preg_match("#" . $kelime . "\\b#", $decod->text)) {
$json = array("error" => true, "mesaj" => "Attığınız tweette " . $kelime . " kelimesi bulunduğu için beğeni işleminiz iptal edildi.");
$yasakli++;
}
}
}
if ($yasakli == 0) {
if ($admin != 1) {
if (urlKontrol == 1 && 0 < count($decode->entities->urls)) {
$yasakli++;
} else {
if (hashtagKontrol == 1 && 0 < count($decode->entities->hashtags)) {
$yasakli++;
} else {
if (mentionKontrol == 1 && 0 < count($decode->entities->user_mentions)) {
$yasakli++;
}
}
}
}
if ($yasakli == 0) {
$json = array("error" => false, "data" => $decod->user->screen_name);
} else {
$json = array("error" => true, "mesaj" => "Attığınız tweette <strong>URL,Hashtags,Mention</strong> bulunduğu için beğeni işleminiz iptal edildi.");
}
}
}
} else {
$json = array("error" => true, "mesaj" => "Twitter ile bağlantı kurulurken bir sorun oluştu. Lütfen daha sonra tekrar deneyin.");
}
} else {
$json = array("error" => true, "mesaj" => "Girdiğiniz link hatalı.Girdiğiniz linki kontrol ettikten sonra tekrar deneyin.");
}
return json_encode($json);
}
Twitter API PHP Hata Alıyorum
1
●130
-
03-06-2024, 15:26:28Selamun Aleyküm dostlar, Anlayan varsa bakabilir mi nerede hata yapıyorum?
-
03-06-2024, 15:29:17Selamlar chatGPT diyorki..
Bu kodun birkaç problemi var. Bunlar arasında güvenlik, kodlama hataları ve anlaşılabilirlik yer alıyor. Öncelikle, fonksiyonu daha anlaşılır hale getirmek ve olası hataları düzeltmek için gözden geçirelim:- sansurKelime, urlKontrol, hashtagKontrol, mentionKontrol gibi değişkenler tanımlanmamış.
- curl_api fonksiyonu tanımlanmamış.
- Güvenlik açısından, consumer_key, consumer_secret, access_token ve access_token_secret gibi değerler doğrudan kod içinde yer almamalı.
function tweetidCheck($id, $admin) { // Tanımlanmamış değişkenler için varsayılan değerler veya gerçek değerler kullanılmalı $sansurKelime = "örnekKelime"; // sansurKelime değerini buraya ekleyin $urlKontrol = 1; // Bu kontrol değişkenlerini ihtiyacınıza göre güncelleyin $hashtagKontrol = 1; $mentionKontrol = 1; if (is_numeric($id)) { $yasakli = 0; $data = file("../token.txt"); shuffle($data); $data = array_reverse($data); $token = json_decode($data[0]); $opt = array( "api_url" => "https://api.twitter.com/1.1/statuses/show.json", "consumer_key" => "3nVuSoBZnx6U4vzUxf5w", "consumer_secret" => "Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys", "access_token" => $token->access_token, "access_token_secret" => $token->access_token_secret, "method" => "GET", "post" => array("id" => $id), "header" => true ); // curl_api fonksiyonunun çalışmasını burada belirtmeliyiz $que = curl_api($opt); if ($que->http_code != 0) { $decode = json_decode($que->content); $hataSorgu = isset($decode->errors) ? $decode->errors : 0; $hata_Sorgu = isset($decode->error) ? $decode->error : 0; if ($hataSorgu != 0 || $hata_Sorgu != 0) { $json = array("error" => true, "mesaj" => "Bilinmeyen bir hata oluştu. Hesabınızın korumalı olup olmadığını kontrol ettikten sonra tekrar deneyin."); } else { if ($admin != 1 && !empty($sansurKelime)) { $bolBakalim = explode(",", $sansurKelime); foreach ($bolBakalim as $kelime) { if (preg_match("#" . $kelime . "\\b#", $decode->text)) { $json = array("error" => true, "mesaj" => "Attığınız tweette " . $kelime . " kelimesi bulunduğu için beğeni işleminiz iptal edildi."); $yasakli++; } } } if ($yasakli == 0) { if ($admin != 1) { if ($urlKontrol == 1 && !empty($decode->entities->urls)) { $yasakli++; } else if ($hashtagKontrol == 1 && !empty($decode->entities->hashtags)) { $yasakli++; } else if ($mentionKontrol == 1 && !empty($decode->entities->user_mentions)) { $yasakli++; } } if ($yasakli == 0) { $json = array("error" => false, "data" => $decode->user->screen_name); } else { $json = array("error" => true, "mesaj" => "Attığınız tweette <strong>URL, Hashtags, Mention</strong> bulunduğu için beğeni işleminiz iptal edildi."); } } } } else { $json = array("error" => true, "mesaj" => "Twitter ile bağlantı kurulurken bir sorun oluştu. Lütfen daha sonra tekrar deneyin."); } } else { $json = array("error" => true, "mesaj" => "Girdiğiniz link hatalı. Girdiğiniz linki kontrol ettikten sonra tekrar deneyin."); } return json_encode($json); }