How to retrieve chat picture?
Closed this issue · 5 comments
SkypeGroupChat has attribute picture
, with content like https://api.asm.skype.com/v1/objects/0-weu-d14-abcdefghij..
, and sometimes like https://experimental-api.asm.skype.com/v1/objects/0-weu-d14-abcdefghij..
.
Retrieving that URL with skpy.Skype.conn("GET", "https://..", auth=skpy.SkypeConnection.Auth.Authorize)
returns result like:
{"id":"0-weu-d14-abcdefghij..",
"type":"avatar/group",
"expiry_date":"3019-09-28T16:03:05.8883653Z",
"contents":{"avatar_fullsize":{"length":750,"full_length":750},
"swx_avatar":{"length":4754,"full_length":4754}},
"geo":"emea"}
But how to get the image itself?
Looking at Skype for Web, it seems to request either of .../views/swx_avatar
or .../views/avatar_fullsize
, the latter of which is returned in the chat metadata and used for the .picture
attribute. Requesting either of them directly seems to give me a JPG:
>>> resp = sk.conn("GET", "https://weu1-api.asm.skype.com/v1/objects/0-weu-.../views/avatar_fullsize",
... auth=SkypeConnection.Auth.Authorize)
>>> resp.headers["Content-Type"]
'image/jpeg'
That said, the .picture
attribute uses the generic domain api.asm.skype.com
rather than the (presumably localised) subdomain that Skype for Web sees, and requesting on the generic domain just returns a 401:
>>> chat = sk.chats["19:...@thread.skype"]
>>> resp = sk.conn("GET", chat.picture, auth=SkypeConnection.Auth.Authorize)
skpy.core.SkypeApiException: ('401 response from GET https://api.asm.skype.com/v1/objects/0-weu-.../views/avatar_fullsize', <Response [401]>)
...so I'm unsure how it discovers the right subdomain to use.
To add insult to injury, sometimes the .picture
attribute already contains the required /views/avatar_fullsize
, but the URL itself gives 401. But changing the domain from api.asm.skype.com
to experimental-api.asm.skype.com
does return the picture.
But when the trailing path is not initially given in .picture
, then any domain seems to work - api.asm.skype.com
, experimental-api.asm.skype.com
, and weu1-api.asm.skype.com
.
Looks like the most robust way is to try all three domains, starting with experimental-api
.. Thank you, that gives me enough information to move forward.
From my side, this issue can be closed. Although SkPy could maybe add this retrieval functionality to its API, as it's already exposing the half-baked picture URL anyway.
An unrelated question, asking it here as GitHub has no private messages - last SkPy release was in October, but there have been a number of commits to master
, like support for retrieving earlier chat history. Do you plan to publish a new release soon, or is master
stable enough to use directly?
About my last question - is master stable enough to use directly, or should I wait for a published release?
maybe add this retrieval functionality
This feels messy, so I'd rather not try and guess how these URLs are supposed to work. If we can find consistent behaviour in Skype for Web then maybe.
is master stable enough to use directly
It's only bug fixes on top of the latest release, so in theory it's no worse. I've been tying up a few loose ends on lingering issues before doing another release.