承接 eugenecooper/tumblr 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eugenecooper/tumblr

Composer 安装命令:

composer require eugenecooper/tumblr

包简介

A unofficial Tumblr API Client for PHP.

README 文档

README

Build Status

An unofficial PHP client for the Tumblr API

Installing

Through the Composer, you must require the package matheusmariano/tumblr.

Using

use MatheusMariano\Tumblr\Client;
use MatheusMariano\Tumblr\Connector\Auth\ApiKey;

$auth = new ApiKey('my-api-key');
$client = new Client($auth);

$object = $client->get('blog/nutright.tumblr.com/posts', [
    'api_key' => true,
    'tag' => 'fruit'
]);

Authentication

Before request any method from API, it's necessary to authenticate our client. To do it, there are two authentication levels:

  • API key
  • OAuth

The API key level is the simplest one, because it just needs the consumer key given by the Tumblr when registering your application. To use this, you should import the ApiKey class

use MatheusMariano\Tumblr\Connector\Auth\ApiKey;

and then instantiate it with your consumer key.

$auth = new ApiKey('your-consumer-key');

You can use the OAuth level practically the same way, importing the OAuth class

use MatheusMariano\Tumblr\Connector\Auth\OAuth;

and then instantiating with all the necessary keys.

$auth = new OAuth; // Also accepts ordered parameters.
$auth->consumerKey = '...';
$auth->consumerSecret = '...';
$auth->oauthToken = '...';
$auth->oauthTokenSecret = '...';

OAuth tokens and Authorizer

Getting the tokens from users is a little bit different task, because they need to be notified and give authorization to your application. It's a proccess that involves a lot of steps, but the Authorizer class turns everything easier. For every used page, you should import the class this way.

use MatheusMariano\Tumblr\Authorizer;

The first step is to send your consumers to Tumblr with your callback URI. Let's consider it should be https://example.com/auth/tumblr/callback.

$auth = new OAuth;
$auth->consumerKey = '...';
$auth->consumerSecret = '...';

$authorizer = new Authorizer($auth);
$tokens = $authorizer->getTemporaryTokens('https://example.com/auth/tumblr/callback');

If consumers are accepted, you should receive temporary tokens.

['oauth_token' => '...', 'oauth_token_secret' => '...']

Save these tokens, because they are necessary for the next session. Now you need to redirect your users to https://www.tumblr.com/oauth/authorize?oauth_token={$tokens['oauth_token']}. There, they are going to be able to authorize your application and then going to be redirected to the callback URI.

In the https://example.com/auth/tumblr/callback, the step is to send the consumers and the temporary tokens together with GET parameter oauth_verifier received from Tumblr.

$auth = new OAuth;
$auth->consumerKey = '...';
$auth->consumerSecret = '...';
$auth->oauthToken = $oauthToken;
$auth->oauthTokenSecret = $oauthTokenSecret;

$authorizer = new Authorizer($auth);
$tokens = $authorizer->getTokens($oauthVerifier);

If you prefer, you can use the global $_GET to get the oauth_verifier.

$oauthVerifier = $_GET['oauth_verifier'];

If everything runs as plained, you should receive the user definitive tokens.

Client

After configure one of those authenticators, you can import the Client class

use MatheusMariano\Tumblr\Client;

and then instantiate it with the authenticator.

$client = new Client($auth);

Methods

In the version 0.1 of this package, the Client has only 2 very basic methods

  • get
  • post

It's important to follow the Tumblr API to use these methods and your responses correctly.

Example: getting the text posts that has the fruit tag.

$object = $client->get('blog/nutright.tumblr.com/posts/text', [
    'api_key' => true,
    'tag' => 'fruit',
]);

The response should be an stdClass object with all content of response, following the Tumblr API.

$object->total_posts; // int
$object->posts; // array
$object->blog; // stdClass
$object->blog->title; // string

The post method works the same way.

$client->post('blog/nutright.tumblr.com/post', [
    'type' => 'text',
    'tags' => 'fruit, apple, red',
    'title' => 'My new post title',
    'body' => 'My new post body...',
]);

Exceptions

Request methods may receive errors, generaly 401 not authorized and 404 not found, throwing exceptions like GuzzleHttp\Exception\ClientException, GuzzleHttp\Exception\ServerException etc., which should be treated with try...catch. See the Guzzle documentation for more information.

try {
    $client->get('blog/nutright.tumblr.com/followers', ['api_key' => true]);
} catch (\GuzzleHttp\Exception\ClientException $e) {
    // Do something
}

License

PHP Tumblr Client a is open-sourced software licensed under the MIT license.

eugenecooper/tumblr 适用场景与选型建议

eugenecooper/tumblr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 07 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「client」 「tumblr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 eugenecooper/tumblr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 eugenecooper/tumblr 我们能提供哪些服务?
定制开发 / 二次开发

基于 eugenecooper/tumblr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-24