2012-08-01 7 views
6

का उपयोग करके Google टॉक से कनेक्ट करें मैं एक जावा एप्लिकेशन विकसित करना चाहता हूं जो Google टॉक से जुड़ता है और उपयोगकर्ता को अपने दोस्तों के साथ चैट करने की अनुमति देता है। मैं स्मैक एपीआई और fallowing कोड का उपयोग कर रहा:स्मैक

ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com",5222,"gmail.com"); 
SASLAuthentication.supportSASLMechanism("PLAIN", 0); 
XMPPConnection connection = new XMPPConnection(config); 
try { 
    connection.connect(); 
} catch (XMPPException e) { 
    e.printStackTrace(); 
} 
try { 
    connection.login("username", "password"); 
} catch (XMPPException e) { 
    e.printStackTrace(); 
} 

लेकिन मैं fallowing अपवाद प्राप्त:

SASL authentication PLAIN failed: invalid-authzid: 
    at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:337) 
    at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203) 
    at org.jivesoftware.smack.Connection.login(Connection.java:348) 
    at Main.main(Main.java:21) 

किसी की मदद कर सकते हैं मुझे इस समस्या को हल करने के लिए?

उत्तर

1

यह वह तरीका है जिसे मैं स्मैक का उपयोग करके Google टॉक से कनेक्ट करने के लिए उपयोग करता था।

private ConnectionStatus status; 
private XMPPConnection xmppConnection; 

public void connect(String server, int port, String s) throws Exception 
{ 
xmppConnection = new XMPPConnection(new ConnectionConfiguration(server, port,s)); 
xmppConnection.connect(); 
xmppConnection.addConnectionListener(this); 
xmppConnection.getChatManager().addChatListener(this); 
} 

और प्रमाणीकरण।

public void authenticate(String username, String password) throws Exception 
{ 
    xmppConnection.login(username, password); 
buddyList.setSession(xmppConnection); 
setStatus(ConnectionStatus.AUTHENITCATED); 
} 
+0

धन्यवाद बचाया, मैं के लिए लॉग इन करने में कामयाब रहे, लेकिन किसी कारण से मैं एक अपवाद प्राप्त करने और मैं डॉन 'क्या करना चाहिए टी इसे कैसे पोस्ट करें –

+0

आप लॉग इन कर सकते हैं लेकिन अपवाद प्राप्त कर सकते हैं? क्या आप पहली पंक्ति पोस्ट कर सकते हैं? – Travis

5

यह दांव, काफी सरल

import org.jivesoftware.smack.Chat; 
import org.jivesoftware.smack.ChatManager; 
import org.jivesoftware.smack.ConnectionConfiguration; 
import org.jivesoftware.smack.MessageListener; 
import org.jivesoftware.smack.XMPPConnection; 
import org.jivesoftware.smack.XMPPException; 
import org.jivesoftware.smack.packet.Message; 
import org.jivesoftware.smack.packet.Presence; 

public class SenderTest 
{ 
public static void main(String args[]) 
{ 
    //ConnectionConfiguration connConfig = new ConnectionConfiguration("localhost", 5222); 
     //connConfig.setSASLAuthenticationEnabled(false); 
    //ConnectionConfiguration connConfig = new ConnectionConfiguration("localhost", 5222); 
    ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); 
     XMPPConnection connection = new XMPPConnection(connConfig); 

     try { 
      connection.connect(); 
      System.out.println("Connected to " + connection.getHost()); 
     } catch (XMPPException ex) { 
      //ex.printStackTrace(); 
      System.out.println("Failed to connect to " + connection.getHost()); 
      System.exit(1); 
     } 
     try { 
      connection.login("[email protected]", "a"); 
      System.out.println("Logged in as " + connection.getUser()); 

      Presence presence = new Presence(Presence.Type.available); 
      connection.sendPacket(presence); 

     } catch (XMPPException ex) { 
      //ex.printStackTrace(); 
      System.out.println("Failed to log in as " + connection.getUser()); 
      System.exit(1); 
     } 

    ChatManager chatmanager = connection.getChatManager(); 
    Chat newChat = chatmanager.createChat("[email protected]", new MessageListener() { 
     public void processMessage(Chat chat, Message message) { 
      System.out.println("Received message: " + message); 
     } 
    }); 

    try { 
     newChat.sendMessage("Howdy!"); 
     System.out.println("Message Sent..."); 
    } 
    catch (XMPPException e) { 
     System.out.println("Error Delivering block"); 
    } 
} 

} 
1

यह मेरा दिन

connectionConfig = new ConnectionConfiguration(host, port, service); 
connectionConfig.setSASLAuthenticationEnabled(false); 
connectionConfig.setTruststoreType("BKS"); 
connection = new XMPPConnection(connectionConfig); 
संबंधित मुद्दे