Tumblr API 获取当前头像 URL [英] Tumblr API get current AVATAR URL

查看:16
本文介绍了Tumblr API 获取当前头像 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Everyone knows? about avatar url in tumblr api / read / json? like for example the facebook?

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

http://graph.facebook.com/[your 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";

?>

如何附加我当前的头像?

how to append my current avatar?

推荐答案

我猜你必须使用

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>

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

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.

或者你可以为头像抓取 tumblelog.

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

这篇关于Tumblr API 获取当前头像 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆