samczsun / Skype4J

Skype API written in Java. Does not support P2P chats
Apache License 2.0
145 stars 48 forks source link

Can't login with a "live:name" account. #110

Open MrPowerGamerBR opened 8 years ago

MrPowerGamerBR commented 8 years ago

(I'm not running 0.2.0 because of the issues I had, so maybe this is already fixed)

If you have an "live:name" account, you can't login (yes, the user is using "live:name", not the email).

If I could I would share more info, but the account isn't mine and I don't have a Skype account with the "live:" prefix.

labotsky commented 8 years ago

I had the same issue. You have only microsoft account, Add Skype account https://secure.skype.com/account/personal/change-password

vforvoid commented 7 years ago

@labotsky Hello. Can you tell me please how had you resolved this issue. It seems like there's no way to create a skype username now, they all linked up with live.com. Any workarounds?

ducc commented 7 years ago

iirc if you have an old ios app you can create non live accounts

MrPowerGamerBR commented 7 years ago

lol I forgot about this issue until now.

Sadly it seems Skype4J is abandoned (because @samczsun is busy with real life) and sadly there isn't any good Skype API for Java (Skype4J is the only one that works, the rest is broken or buggy)

ducc commented 7 years ago

abandoned is the wrong word. "inactive"

MrPowerGamerBR commented 7 years ago

@sponges so what would be a better word? Unmaintained?

Kadkad195 commented 6 years ago

Hi there, dont know if you solved it yet, I found out that it is because skype4j use https://api.skype.com/login/skypetoken api, which you can find here: https://github.com/msndevs/protocol-docs/wiki/Authentication

My solution is i extends FullClient class and Override login() method. So that i dont have to use that api to get token.

public class MyFullClient extends FullClient {

public MyFullClient(String username, String password, Set<String> resources, Logger customLogger, List<ErrorHandler> errorHandlers) {
    super(username, password, resources, customLogger, errorHandlers);
}

@Override
public void login() throws InvalidCredentialsException, ConnectionException {
    this.setSkypeToken("eyJhbGciOiJSUzI1NiIsImtpZCI6IjEzIiwidHlwIjoi....."); //Here is your skype token
    List<UncheckedRunnable> tasks = new ArrayList<>();
    tasks.add(() -> {
        HttpURLConnection asmResponse = getAsmToken();
        String[] setCookie = asmResponse.getHeaderField("Set-Cookie").split(";")[0].split("=");
        this.cookies.put(setCookie[0], setCookie[1]);
    });
    tasks.add(this::loadAllContacts);
    tasks.add(() -> this.getContactRequests(false));
    tasks.add(() -> {
        try {
            this.registerWebSocket();
        } catch (Exception e) {
            handleError(ErrorSource.REGISTERING_WEBSOCKET, e, false);
        }
    });
    tasks.add(this::registerEndpoint);

    try {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        tasks.forEach(executorService::submit);
        executorService.shutdown();
        executorService.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}

}

as you can see: this.setSkypeToken("a long token string");, this is where you insert your skypetoken, which you can get from another api: https://docs.microsoft.com/en-us/bot-framework/rest-api/bot-framework-rest-connector-authentication (which you can login with email or phone number)

Then create a custom SkypeBuilder class

public class KadSkypeBuilder {

private final String username; private final String password;

private Set<String> resources = new HashSet<>();
private List<ErrorHandler> errorHandlers = new ArrayList<>();
private Logger customLogger;
private String chatId;

/**
 * Construct a KadSkypeBuilder with the given username and password
 *
 * @param username The username
 * @param password The password
 */
public KadSkypeBuilder(String username, String password) {
    this.username = username;
    this.password = password;
}

/**
 * Construct a KadSkypeBuilder using the given guest username
 *
 * @param username The guest username (Can be anything)
 */
public KadSkypeBuilder(String username) {
    this.username = username;
    this.password = null;
}

/**
 * Subscribe to all known resources
 *
 * @return The same KadSkypeBuilder 
 */
public KadSkypeBuilder withAllResources() {
    resources.addAll(Arrays.asList("/v1/users/ME/conversations/ALL/properties", "/v1/users/ME/conversations/ALL/messages", "/v1/users/ME/contacts/ALL", "/v1/threads/ALL"));
    return this;
}

/**
 * Subscribe to a resource which has not been added into the API
 *
 * @param resource The resource to subscribe to
 * @return The same KadSkypeBuilder 
 */
public KadSkypeBuilder withResource(String resource) {
    resources.add(resource);
    return this;
}

/**
 * Use a custom logger for this Skype instance
 *
 * @param logger The custom logger to use
 * @return The same KadSkypeBuilder 
 */
public KadSkypeBuilder withLogger(Logger logger) {
    this.customLogger = logger;
    return this;
}

/**
 * Add an exception handler to handle exceptions
 *
 * @param errorHandler The exception handler
 * @return The same KadSkypeBuilder 
 */
public KadSkypeBuilder withExceptionHandler(ErrorHandler errorHandler) {
    this.errorHandlers.add(errorHandler);
    return this;
}

/**
 * Join a particular chat as a guest. Will have no effect if a password is specified
 *
 * @param id The chat id
 * @return The same KadSkypeBuilder 
 */
public KadSkypeBuilder withChat(String id) {
    if (!id.startsWith("19:")) throw new IllegalArgumentException("Invalid chat id");
    if (password != null) throw new IllegalArgumentException("Not guest account");
    this.chatId = id;
    return this;
}

/**
 * Build the Skype instance!
 *
 * @return The Skype instance
 */
public Skype build() {
    if (resources.isEmpty()) {
        throw new IllegalArgumentException("No resources selected");
    }
    if (password != null) {
        return new MyFullClient(username, password, resources, customLogger, errorHandlers);
    } else if (chatId != null) {
        return new MyFullClient(username, chatId, resources, customLogger, errorHandlers);
    } else {
        throw new IllegalArgumentException("No chat specified");
    }
}

}

finally, using custom KadSkypeBuilder

public static void main(String[] args) throws ConnectionException, InvalidCredentialsException, NotParticipatingException {
    Skype skype = new KadSkypeBuilder("username", "pass").withAllResources().build();
    skype.login();
    skype.getEventDispatcher().registerListener(new Listener() {
        @EventHandler
        public void onMessage(MessageReceivedEvent e) throws ConnectionException {
            if (e.getMessage().getContent().asPlaintext().equals("time")) {
                e.getChat().sendMessage("Test");
            }
            System.out.println("Got message: " + e.getMessage().getContent());
        }
    });
    skype.subscribe();
}

Hope this help