• 18-02-2025, 00:14:12
    #1
    Merhaba arkadaşlar

    Wordpress function.php dosyasına şu kodlar üzerinden twitter.com/profiladı bileşen kısmından yazıldığında hangi profil yazılırsa yazılsın onun takipçi sayısını sidebar kısmında gösterecek

    developer üzerinden bearer token verdiği kodu ekledim ama error hatası veriyor tam olarak gözden kaçan kısım neresi

    hatat kullanıcı kimlik doğruma form doldurdum yeşil tik oldu

     private function get_twitter_followers($url)
        {
            $bearer_token = 'BURAYA DEVELOPER TWİTTER ALDIĞIM BEARER TOKEN KODUNU YAZDIM AMA ÇALIŞMADI';
            $username = '';
            if (preg_match('/(?:x\.com|twitter\.com)\/([^\/?]+)/i', $url, $matches)) {
                $username = trim($matches[1]);
            }
            if (empty($username)) {
                return 'Error: Invalid Twitter URL';
            }
    
            $user_lookup_url = "https://api.twitter.com/2/users/by/username/{$username}";
            $response = wp_remote_get($user_lookup_url, array(
                'headers' => array(
                    'Authorization' => "Bearer {$bearer_token}"
                )
            ));
            if (is_wp_error($response)) {
                return 'Error: Failed to fetch user data';
            }
        
            $data = json_decode(wp_remote_retrieve_body($response), true);
            error_log(print_r($data, true));
            
            if (!isset($data['data']['id'])) {
                return 'Error: Invalid username or API response';
            }
            $user_id = $data['data']['id'];
        
            $followers_url = "https://api.twitter.com/2/users/{$user_id}?user.fields=public_metrics";
            $response = wp_remote_get($followers_url, array(
                'headers' => array(
                    'Authorization' => "Bearer {$bearer_token}"
                )
            ));
            if (is_wp_error($response)) {
                return 'Error: Failed to fetch followers count';
            }
            $data = json_decode(wp_remote_retrieve_body($response), true);
            error_log(print_r($data, true));
          
            if (isset($data['data']['public_metrics']['followers_count'])) {
                return number_format($data['data']['public_metrics']['followers_count']) . ' followers';
            }
            return 'Error: Could not retrieve followers count';
        }
  • 18-02-2025, 00:16:22
    #2
    twitterdan response olarak ne dönüyor atar mısın?
  • 18-02-2025, 00:17:13
    #3
    webandmob adlı üyeden alıntı: mesajı görüntüle
    twitterdan response olarak ne dönüyor atar mısın?
    Error: Invalid username or API response followers
  • 18-02-2025, 00:23:41
    #4
    22. satırda requestten dönen response json decode ediliyor edildikten sonra onu yazdırıp yollayabilir misiniz? (error_log un içine yazıyor)