delthas / JavaSkype

A lightweight, comprehensive Java API for Skype using MSNP24
MIT License
72 stars 28 forks source link

getAvatar(...) returns "{"status":{"code":40300,"text":"Skypetoken Authorization failed"}}" #20

Closed MrPowerGamerBR closed 7 years ago

MrPowerGamerBR commented 7 years ago

Edited the getAvatar(...) method in the WebConnector class to print the body (to find out how can I transform the bytes into a BufferedImage) and...

{"status":{"code":40300,"text":"Skypetoken Authorization failed"}}
delthas commented 7 years ago

Could you send me the debug log files please? (enable debugging with the Skype.setDebug function)
Thanks :)

MrPowerGamerBR commented 7 years ago

@Delthas https://gist.github.com/MrPowerGamerBR/1ac36d7c7a556bd6e23d4532a2f7a218

package com.mrpowergamerbr.sparklywhistlerbot.utils;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.mrpowergamerbr.sparklywhistlerbot.Whistler;
import com.mrpowergamerbr.temmiewebhook.DiscordMessage;
import com.mrpowergamerbr.temmiewebhook.TemmieWebhook;

import fr.delthas.skype.Group;
import fr.delthas.skype.Skype;
import fr.delthas.skype.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

public class DebugSkype {
    static Skype skype;

    public static void main(String[] args) {    
        skype = new Skype(SuperSecret.username, SuperSecret.password);
        try {
            // If you want to report a bug, enable logging
            Skype.setDebug(new File("C:\\Users\\Whistler\\Documents\\skype.log").toPath());
            skype.connect(); // Will block until we're connected

            // Create a simple time bot
            skype.addUserMessageListener((user, message) -> {
              if (message.toLowerCase().contains("time")) {
                  user.getAvatar();
                user.sendMessage("The current time is: " + LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
              }
            });

            for (User user : skype.getContacts()) {
                System.out.println(user.getDisplayName());
            }
        } catch (IOException | InterruptedException e) {
            System.err.println("An error occured while connecting...");
            e.printStackTrace();
        }

        skype.setErrorListener(Exception::printStackTrace);
    }
}
MrPowerGamerBR commented 7 years ago

@Delthas I may be wrong, but isn't the auto_key missing from the request?

This link works

https://avatar.skype.com/v1/avatars/craft.elite?auth_key=1793005082

But there also another link that also works if the user avatar is public

https://avatar.skype.com/v1/avatars/xhiroshi_/public

(I found that out while looking the Skype dump from my #22 issue)

And this is this the code used to get the avatar (which doesn't work)

  public byte[] getAvatar(User user) throws IOException {
    return sendRequest(Method.GET, "/users/" + user.getUsername() + "/profile/avatar").bodyAsBytes();
  }

Or maybe you can use both types of authentication... then just ignore this message...

MrPowerGamerBR commented 7 years ago

And after more debugging, it seems that the ONLY avatar that it can get successfully is the user own avatar.

delthas commented 7 years ago

Yeah, I used to use an auth key but I think I removed it because a few months ago using an auth key or non didn't change anything. Maybe they changed that. I'll try and fix this.

delthas commented 7 years ago

I think I have fixed this in 1.0.18 (that I just pushed). Does it actually work? :)

MrPowerGamerBR commented 7 years ago

@Delthas testing it as soon as possible :)

(Also, can you add a method to get the user avatar URL? It would be helpful :) )

delthas commented 7 years ago

Yes I can, I don't really know what's the purpose of that but I'll add it right now.

MrPowerGamerBR commented 7 years ago

@Delthas Discord Webhooks allows setting the user avatar via a link.

So you can change the message avatar by just changing the user avatar URL.

Yeah, a very niche case.

delthas commented 7 years ago

Oh, that's actually pretty cool! I'll add it.

MrPowerGamerBR commented 7 years ago

@Delthas like this

http://i.imgur.com/pmvuuSA.png (I'm using a Skype public API URL to get those avatars... as you can see it doesn't get all avatars successfully... that's why I asked a method to get the avatar URL)

This is a Skype chat -> Discord (vice-versa also works), created using JavaSkype, https://github.com/MrPowerGamerBR/TemmieWebhook and https://github.com/DV8FromTheWorld/JDA

I had this idea in mind since a loooong time, however I never done it because there wasn't a good (and working!) Skype API for Java, and now... there is. 😄

delthas commented 7 years ago

Very nice project! I have pushed 1.0.19 which contains a new User#getAvatarUrl() method. Does it work well? @MrPowerGamerBR