mehov / xmpphp

Automatically exported from code.google.com/p/xmpphp
0 stars 0 forks source link

get contacts problem in gtalk #111

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
   I am using following code to retrieve contacts

include 'XMPPHP/XMPP.php';
$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'xxxxxxx', 'xxxxxxx', 
'xmpphp', 'gmail.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);

try {
    $conn->connect();
    $conn->processUntil('session_start');
    $conn->getRoster();
   $conn->disconnect();
} catch(XMPPHP_Exception $e) {
    die($e->getMessage());
}

but no contacts found.I am using linux server with php 5.3.5.Please help me to 
sort out this problem.

Original issue reported on code.google.com by tariqm...@gmail.com on 21 Jun 2011 at 7:30

GoogleCodeExporter commented 9 years ago
I also can`t get the firends list. any body can help me ? 

Original comment by lucky.zh...@gmail.com on 13 Jun 2012 at 7:37

GoogleCodeExporter commented 9 years ago
From this code you will get Roster information of your friends

<?php

include 'XMPP.php';

function array_contactos($user,$pass){
    #Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
    #If this doesn't work, are you running 64-bit PHP with < 5.2.6?
    $conn = new XMPPHP_XMPP('talk.google.com', 5222, $user,$pass, "xmpphp", 'gmail.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);
    $conn->autoSubscribe();

    $vcard_request = array();

    try {
        $conn->connect();
        while(!$conn->isDisconnected()) {
            $payloads = $conn->processUntil(array('end_stream', 'session_start','roster_received'));
            foreach($payloads as $event) {
                $pl = $event[1];
                switch($event[0]) {

                    case 'session_start':
                    //  print "Session Start\n";
                        $conn->getRoster();
                        $conn->presence($status="Cheese!".time());
                        print_r($p1);

                    break;

                    case 'roster_received':
                    $array_contactos=$pl;
                    return $array_contactos;
                    /*
                    foreach($array_contactos as $user => $mostrar_nombre){
                        echo $user.'<br>';
                        echo $mostrar_nombre['name'];
                        echo '<hr>';
                    }*/

                    $conn->disconnect();
                    break;
                }
            }       
        }
    } catch(XMPPHP_Exception $e) {
        die($e->getMessage());
    }

}
$user_="xxxxxxxxxxxxxx";
$pass_='xxxxxxxxxxxxxx';

$results= array_contactos($user_,$pass_);

echo "<pre>";
print_r($results);
echo "</pre><br><br>";

foreach($results as $users => $mostrar_name){
    echo $users.'<br>';
    echo $mostrar_name['name'];
    echo '<hr>';
}

Original comment by jay.vinf...@gmail.com on 4 Jul 2012 at 5:42