使用 taskan 的 java-skype api 用 Java 发送 Skype 消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27931802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending Skype messages in Java, using the java-skype api by taskan
提问by Stefan x
I need help with my java project. I'm currently trying to send a message in a Skype conversation when a specific action happens.
我的 Java 项目需要帮助。我目前正在尝试在发生特定操作时在 Skype 对话中发送消息。
For this, I am using the java-skype API v1.4 by taskan.
为此,我使用taskan的java-skype API v1.4。
Here's my code:
这是我的代码:
try {
for (Group group : Skype.getContactList().getAllGroups()) {
if ((group.getDisplayName()).equals("Nameofthegroup")) { //Whatever the group name is
String id = group.getId();
Skype.chat(id).send(ep.getDisplayName() + " joins !");
ep.sendMessage("Die ID: "+ id);
}
}
} catch (Exception e3) {
e3.printStackTrace();
}
I've also tried:
我也试过:
try {
String id = Skype.getContactList().getGroup("Groupname").getId();
Skype.chat(id).send(p + "joins!");
} catch (SkypeException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
My problem is that Skype registers that a external program tries to do something, but after I allow access for Java, nothing else happens. No messages are sent.
我的问题是 Skype 注册了一个外部程序试图做某事,但是在我允许 Java 访问之后,没有其他任何事情发生。不发送任何消息。
回答by Little Jacod
Sorry for the late answer but assuming you haven't yet picked an answer the problem is still open.
抱歉回答晚了,但假设您还没有选择答案,问题仍然存在。
I was trying to get groups the same way with you but unfortunately it doesn't work like this. I do not if this is API problem or just because microsoft dropped support from third party APIssome of its features not working.
我试图以与您相同的方式获得团体,但不幸的是它不能像这样工作。如果这是 API 问题,或者仅仅是因为微软放弃了对第三方 API 的支持,它的某些功能不起作用,我不会。
I managed to work this around by searching for chats not for groups. Also it would be much easier if you just bookmark (add at favorites) the chat (group) you want to find.
我设法通过搜索聊天而不是群组来解决这个问题。此外,如果您只是为要查找的聊天(组)添加书签(添加到收藏夹),这会容易得多。
Chat group = null;
for ( Chat c : Skype.getAllBookmarkedChats() ){
group = c;
}
I just have the group chat in my favorites so it is super easy to retrieve it! If you have more chats and you need a more general way to find a specific one there are also several ways to do this.
我只是在我的收藏夹中有群聊,因此检索它非常容易!如果您有更多的聊天记录,并且需要一种更通用的方法来查找特定的聊天记录,那么也有多种方法可以做到这一点。
for (Chat c : Skype.getAllChats()){
c.getAllMembers();
c.getId();
c.getWindowTitle();
}
group = c;
But this would be harder. The getId() way may be look easier but I didn't manage to get it working. Don't know again if it was my problem or just the API but whatever I tried simple just didn't work. And do not forget to print your results at console to ease yourself.
但这会更难。getId() 方式可能看起来更简单,但我没有设法让它工作。不知道是我的问题还是 API 的问题,但是我尝试的任何简单方法都不起作用。并且不要忘记在控制台打印您的结果以减轻您的负担。
In the end if you manage to get your group chat it is really easy to send a message:
最后,如果您设法进行群聊,发送消息真的很容易:
group.send("Hi chat! This is java!!");
EDIT
编辑
This api works only for p2p chats. If you want to create a p2p chat you need to use the /createmoderatedchatcommand in any chat and it will create a new empty p2p chat. Any other group will be automatic cloud-based.
此 api 仅适用于 p2p 聊天。如果你想创建一个 p2p 聊天,你需要在任何聊天中使用/createmoderatedchat命令,它会创建一个新的空 p2p 聊天。任何其他组都将自动基于云。
Also check this
也检查这个
SECOND EDIT
第二次编辑
API is completely dead
API 完全死了
回答by Captain_D1
I don't know too much about the Skype API, but you can check the samplesfor help. If you want to send a chat message when someone sends you a chat message you can use the AutoAnswering example:
我对 Skype API 不太了解,但您可以查看示例以获取帮助。如果您想在有人向您发送聊天消息时发送聊天消息,您可以使用自动应答示例:
package com.skype.sample;
import com.skype.ChatMessage;
import com.skype.ChatMessageAdapter;
import com.skype.Skype;
import com.skype.SkypeException;
public class AutoAnswering {
public static void main(String[] args) throws Exception {
Skype.setDaemon(false); // to prevent exiting from this program
Skype.addChatMessageListener(new ChatMessageAdapter() {
public void chatMessageReceived(ChatMessage received) throws SkypeException {
if (received.getType().equals(ChatMessage.Type.SAID)) {
received.getSender().send("I'm working. Please, wait a moment.");
}
}
});
}
}
Your code has an undefined variable ep
in it and I can't give you a better answer because of that. I would've made a comment asking about it, but Stack Overflow doesn't let new people make comments.
您的代码中有一个未定义的变量ep
,因此我无法给您更好的答案。我会发表评论询问它,但 Stack Overflow 不允许新人发表评论。