Google Talk Status Update

I’ve spent the whole day trying to update my gtalk status automatically, but can’t seem to find out what’s wrong. I’m guessing it has to do with the bit on status updates on the Google Talk API page (see below).

Here’s my smack code:

// XMPP connection

**ConnectionConfiguration **cc = new ConnectionConfiguration(“talk.google.com”, 5222, “gmail.com”);

**XMPPConnection **connection = new XMPPConnection(cc);

try

{

// Connect

System.out.print("Connecting... ");

connection.connect();

System.out.println("Done!");



// Login

System.out.print("Logging in... ");

SASLAuthentication.supportSASLMechanism("PLAIN", 0);

connection.login("someuser@gmail.com", "pwd");

System.out.println("Authenticated? " + connection.isAuthenticated());



// New presence

**Presence **presence = new **Presence**(Presence.Type.available);

presence.setMode(Presence.Mode.available);

presence.setStatus("Some status");

presence.setPriority(24);



// Sending new presence

System.out.print("Setting status... ");

connection.sendPacket(presence);

System.out.println("Done!");

}

**catch **(**XMPPException **e)

{

e.printStackTrace();

}

From the google page:

Google Talk User Status

If a user has “subscribed” to an app (has accepted an invitation or has invited the app to chat), the app can query whether a Google Talk user has a chat client running using the XMPP service API. The app can detect two possible status values: the user is connected, or the user is not connected. The app cannot determine the “away” status, nor can it determine the user’s status message.

An app can only query the status of Google Talk users, and only those that have “subscribed” to the app. There is no way for an XMPP service to query the status of users on other XMPP services.

App Engine reports a status of connected and available for all applications, regardless of whether the app supports receiving XMPP messages. There is no way to set a status message for an app.

Oh, and the application appears to be working.

Here’s my output:

Connecting… Done!
Logging in… Authenticated? true
Setting status… Done!

According to this page on the Google’s site, one has to set the presence in the following manner:


<iq type='set' to='romeo@gmail.com/orchard' id='ss-2'>
  <query xmlns='google:shared-status' version='2'>
    <status>**Juliet's here**</status>
    <show>default</status>
    <status-list show='default'>
        <status>Juliet's here</status>
        <status>Pining away</status>
        <status>Wherefor indeed</status>
        <status>Thinking about the sun</status>
    </status-list>
    <status-list show='dnd'>
        <status>Chilling with Mercutio</status>
        <status>Visiting the monk</status>
    </status-list>
    <invisible value='false'/>
  </query>
</iq>

Is there any way to send a string to the XMPP server without using the Presence class? I suppose one can delve into the source code, but that’s plan B at this stage.

I wrote a class that should get you started. The Google documentation you referenced is either wrong or misleading. When you send a query packet, the to="" should not contain the client’s identifier (in the examples its ‘orchard’). Using my class will erase your saved status messages, however. Google says you can get the current ones and resend them, but I couldn’t get it working.

class gtalksharedStatusPacket extends Packet {
     
     private String loginname;
     private String status;
     private int type;
     
     
     public gtalksharedStatusPacket (String _loginname) {
          loginname = _loginname;
     }
     
     public gtalksharedStatusPacket (String _loginname, String _status) {
          loginname = _loginname;
          status = _status;
          type = 3;
     }
     
     public void setType (int _type) {
          type = _type;
     }
     
     public void setStatus (String _status) {
          status = _status;
     }
     
     public String toXML () {
          String output = "";
          
          switch (type) {
               case 1: //client service discovery request
                    output += "<iq type='get' to='gmail.com'>";
                    output += "<query xmlns='http://jabber.org/protocol/disco#info'/>";
                    output += "</iq>";
                    break;
               
               case 2: //client request for status list
                    output += "<iq type='get' to='"+loginname+"@gmail.com'
id='"+Packet.nextID()+"' >";
                    output += "<query xmlns='google:shared-status' version='2'/>";
                    output += "</iq>";
                    break;
                    
               case 3: //update status
                    output  = "<iq type='set' to='"+loginname+"@gmail.com'
id='"+Packet.nextID()+"'>";
                    output += "<query xmlns='google:shared-status' version='2'>";
                    output += "<status>"+status+"</status>";
                    output += "<show>default</show>";
                    output += "<invisible value='false'/>";
                    output += "</query>";
                    output += "</iq>";
          }
          return output;
     }
}

Just send a gtalksharedStatusPacket with XMPPConnection.sendPacket().

Shot Brad! I’ll give it a go.

Thanks

Hello Brad,

I am trying to retrieve the list of recent status messages from something exactly same like your class but getting nothing and when I tried your class to get it, the problem remains the same. I tried to do exactly as discribed on http://code.google.com/apis/talk/jep_extensions/shared_status.html

I used:

and in response I get:

<item…

Its the same story with every gtalk extension query, Service discovery is working fine but getting nothing in processing any extension query. Can you help with this?