我正在使用XMPPHP来检索我的应用程序用户GMail帐户的名单
XMPPHP能告诉我名册联系人的在线状态吗?
我似乎无法找到如何做到这一点......
欢呼声。
答案 0 :(得分:2)
以下是名单列表和GMail用户在线存在的示例;
$user_name = 'ENTER_EMAIL_ID';
$password = 'ENTER_PASSWORD';
$end_loop = 0;
$conn = new XMPPHP_XMPP('talk.google.com', 5222, $user_name,$password, "xmpphp", 'gmail.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);
$conn->autoSubscribe();
try {
$conn->connect();
while($end_loop <=0) {
$payloads = $conn->processUntil(array('end_stream', 'session_start','roster_received'));
foreach($payloads as $event) {
$pl = $event[1];
switch($event[0]) {
case 'session_start':
$conn->getRoster();
$conn->presence('I m presence'.time());
break;
case 'roster_received':
$array_contact=$pl;
foreach($array_contact as $user => $friends_name){
echo "<li>".$user.'_NAME_'.$friends_name['name'].'</li>';
}
$end_loop++;
break;
}
}
}
while(1)
{
$payloads = $conn->processUntil(array('presence'));
echo "<li>".$payloads[0][1]['from']."_Show_". $payloads[0][1]['show']."</li>";
$_SESSION[$payloads[0][1]['from']] = "~~";
}
$conn->disconnect();
} catch(XMPPHP_Exception $e) {
die($e->getMessage());
}
答案 1 :(得分:0)
我没有尝试使用Google Talk,但通常你正在寻找
$roster->getPresence($jid)['status']
答案 2 :(得分:0)
$uStatus = $conn->roster->getPresence($jid);
echo "Online status: " . $uStatus['show']; // tells whether available or unavailable or dnd
echo "Status message: " . $uStatus['status']; // shows the user's status message
答案 3 :(得分:0)
我在这里发布了一个类似问题的答案:XMPPHP GTalk Status
以下是让它发挥作用的关键:
对我来说,另一个关键是打开详细记录。你在初始对象构造中这样做:
$conn = new XMPPHP_XMPP('talk.google.com', 5222, $user_name,$password, "xmpphp", 'gmail.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);
这将输出一个详细的日志到您的输出(在我的情况下是浏览器窗口)。