Tumblr API get current AVATAR URL

旧时模样 提交于 2019-12-04 10:53:49

I guess you have to use

GET http://www.tumblr.com/api/authenticate?email=user@example.com&password=12345

to get the avatar of the user. The sample response for mine is

<tumblr version="1.0">
<user default-post-format="html" can-upload-audio="1" can-upload-aiff="1" can-ask-question="1" can-upload-video="1" max-video-bytes-uploaded="26214400" liked-post-count="134"/>
<tumblelog title="ABNKKPGPiCTuReNPLaKo?!" is-admin="1" posts="301" twitter-enabled="0" draft-count="0" messages-count="0" queue-count="" name="arvn" url="http://arvn.tumblr.com/" type="public" followers="17" avatar-url="http://28.media.tumblr.com/avatar_b1786ec9e62d_128.png" is-primary="yes" backup-post-limit="30000"/>
<tumblelog title="i kras yu." is-admin="1" posts="1" twitter-enabled="0" draft-count="0" messages-count="0" queue-count="" name="ikrasyu" url="http://ikrasyu.tumblr.com/" type="public" followers="2" avatar-url="http://25.media.tumblr.com/avatar_02a7ef66fce8_128.png" backup-post-limit="30000"/>
</tumblr>

and get the avatar-url field of the corresponding tumblelog. Too bad there is no json format option, maybe use preg_match. You also need the email address and password of the user, or do it via OAuth.

Or you could scrape the tumblelog for the avatar.

$page = file_get_contents("http://{$tumblog}.tumblr.com/");
$avatar = preg_match('/<img src="(http.+)" alt="portrait"/', $page, $matches) ? $matches[1]: 'http://example.com/blank.png';

A better solution for this is to put the Avatar api in an img tag.

api.tumblr.com/v2/blog/{base-hostname}/avatar[/size]

example: <img src='http://api.tumblr.com/v2/blog/myreallycoolblog.tumblr.com/avatar/48'/>

So as long as you have the blogname, you can display the avatar.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!