【问题标题】:Tumblr API get current AVATAR URLTumblr API 获取当前头像 URL
【发布时间】:2011-06-09 07:05:04
【问题描述】:

大家都知道吗?关于 tumblr api/read/json 中的头像 url? 比如脸书?

http://graph.facebook.com/[你的 facebook id]/picture?type=normal

<?php
$tumblog = 'natadec0c0'; // change to your username
// if your Tumblog is self hosted, you need to change the base url to the location of your tumblog
$baseurl = 'http://' . $tumblog . '.tumblr.com';
$request = $baseurl . '/api/read/json';
$ci = curl_init($request);
curl_setopt($ci,CURLOPT_RETURNTRANSFER, TRUE);
$input = curl_exec($ci);
curl_close($ci);

// Tumblr JSON doesn't come in standard form, some str replace needed

$input = str_replace('var tumblr_api_read = ','',$input);
$input = str_replace(';','',$input);

// parameter 'true' is necessary for output as PHP array

$value = json_decode($input,true);
$content =  $value['posts'];
$blogInfo = $value['tumblelog'];

// the number of items you want to display
$item = 10;

// Echo the blog info
echo "<h3><a href=\"" . $baseurl . "\">" . $blogInfo['title'] . "</a></h3>\n";
echo "<h4>" . $blogInfo['picture'] . "</h4>\n<hr />\n";

?>

如何添加我当前的头像?

【问题讨论】:

    标签: tumblr


    【解决方案1】:

    更好的解决方案是将 Avatar api 放在 img 标签中。

    api.tumblr.com/v2/blog/{base-hostname}/avatar[/size]
    
    example: <img src='http://api.tumblr.com/v2/blog/myreallycoolblog.tumblr.com/avatar/48'/>
    

    所以只要有博客名,就可以显示头像。

    【讨论】:

    • 对我来说,我必须包括/blog/,又名&lt;img src='http://api.tumblr.com/v2/blog/myreallycoolblog.tumblr.com/avatar/48'/&gt;
    【解决方案2】:

    我猜你必须使用

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

    获取用户的头像。我的样本响应是

    <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>
    

    并获取相应 tumblelog 的 avatar-url 字段。太糟糕了,没有 json 格式选项,也许使用 preg_match。您还需要用户的电子邮件地址和密码,或者通过OAuth进行。

    或者你可以从 tumblelog 中获取头像。

    $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';
    

    【讨论】:

    • 谢谢您,先生,但是关于没有 OAuth? amm 就像这个网站tumbletrain.com 尝试添加您的 tumblr 用户名.. 然后刷新页面它会自动添加您的 tumblr 照片...它是如何完成的?先生:)
    • @marc 最好的办法是他们获取 tumblelog 页面并查找此 &lt;img src="AVATAR_URL" alt="portrait"。尝试添加一个不在主页上显示其头像的 tumblelog。
    • @marc 我编辑了答案以添加该选项;抓取页面
    • 哇哇哇哇,我会这个兄弟.. :) 等一下.. :)
    • @alvin owhh 是的,哈哈,对不起,我忘记了,:) 我刚来@stackoverflow ;) 顺便说一句,兄弟 pinoy ka pala .. :) 哇,pwde hingi ng ym mo bro? ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 2014-01-03
    • 2011-03-13
    • 2023-03-12
    相关资源
    最近更新 更多