最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to retrieve user avatar from a Trello API? - Stack Overflow

programmeradmin6浏览0评论

trello API gives only hashes, such as avatarHash, gravatarHash, uploadedAvatarHash etc. Is there any way to retrieve an image url from these hashes?

trello API gives only hashes, such as avatarHash, gravatarHash, uploadedAvatarHash etc. Is there any way to retrieve an image url from these hashes?

Share Improve this question asked Sep 16, 2016 at 8:02 mcmxcmcmxc 5941 gold badge7 silver badges19 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 5

Trello uses Gravatar, so the hash you're getting back relates directly to that.

Base URL would be: http://www.gravatar./avatar/

You can add on jpg and size between 1 and 512.

An example:

http://www.gravatar./avatar/ [the hash here] .jpg?s=80

Will give back 80px avatar

function get_gravatar(hash, size) {           
    var size = size || 80;

    return 'http://www.gravatar./avatar/' + hash + '.jpg?s=' + size;
}

Using this hash you can retrieve an image by url: http://trello-avatars.s3.amazonaws./${avatarHash}/50.png

As at 14 July 2020 the correct URL path is as follows:

https://trello-members.s3.amazonaws./{member.id}/{member.avatarHash}/{size}.png

Note: this doesn't seem to work any arbitrary size value, however it does work for size = 170.

Alas, as of 2020-05-05, both these answers don’t work.

  1. gravatarHash solution works to get an avatar from Gravatar, but I’m not sure that solution ever worked as stated from the Trello API’s returned avatarHash, as the Trello API returns an opaque avatarHash which is NOT the same as a gravatarHash. According to Gravatar APis they are a trimmed, lowercased, MD5’ed email address. So gravatarHash ≠ Trello avatarHash.

  2. https://trello-avatars.s3.amazonaws./{avatarHash}/50.png now 403s. Trello devs made a change.

New solution: Use https://trello-members.s3.amazonaws./{id}/{avatarHash}/50.png

Where {id} is the member/user id and {avatarHash} is the same retrieved from the Trello API. That same API allows you to specify returning id as well, so add that to the list of fields with the API call.

In validating by looking at avatars on Trello. they do, in fact, only seem to use this trello-members URL.

This is returned in the same data response if you add the field avatarUrl.

I have updated our Gmail-2-Trello Chrome Extension (https://g2t.pub/chrome) and it’s working correctly with this new pattern.

发布评论

评论列表(0)

  1. 暂无评论