定制 benkle/deviantart 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

benkle/deviantart

Composer 安装命令:

composer require benkle/deviantart

包简介

Access to DeviantARTs oAuth2 API

README 文档

README

This library can be used to access []deviantARTs official oAuth2 API](https://www.deviantart.com/developers/), abstracting away authorization, request building and response parsing. Well, a little bit, anyway...

Requirements

Installation

The Library can be included in the usual way with composer:

    composer require benkle/deviantart

Usage

First you need to create an instance of Seinopsys' oAuth provider for the library to use:

use \SeinopSys\OAuth2\Client\Provider\DeviantArtProvider;

$provider = new DeviantArtProvider(
    [
        'clientId'     => 'YOUR ID',
        'clientSecret' => 'YOUR SECRET',
        'redirectUri'  => 'YOUR REDIRECT URL',
    ]
);

Next, you need to procure a stored token.

// Must return an instance of \League\OAuth2\Client\Token\AccessToken or null
$accessToken = PROCURE_ACCESS_TOKEN();

Now you can wrap the Api class around them.

use \Benkle\Deviantart\Api;

$api = new Api($provider, $accessToken);

And finally, Authorization!

use \Benkle\Deviantart\Exceptions\UnauthorizedException;

try {
    $scopes = [Api::SCOPE_BROWSE];
    $api->authorize($scopes);
    // authorize() will refresh the token, if necessary, so you might want to write it back to storage.
    // You can access it via $api->getAccessToken()
} catch (UnauthorizedException $e) {
    // Here you can handle the initial user input for authorization.
    // The exception message has been replaced with the URL you need to call, so you can get it easily like this:
    $url = "$e";
}

In case you are in the handler called by initial authorization, you can hand the auth code as a second parameter to authorize:

    $api->authorize($scopes, $authCode);

Once you've done all that, you can use the API, e.g. like this:

try {
    /** @var \stdClass $result */
    $result = $api->browse()->getNewest();
} catch (ApiException $e) {
    // Handle API exception
}

The endpoints are grouped into sub-object in accordance with the documentation and will return instances of \stdClass.

The only exception of this rule is the sta.sh submit, which returns the ApiRequest used so adding parts is easier:

use \Benkle\Deviantart\ApiRequestPart;

try {
    /** @var \stdClass $result */
        $result = $api
            ->stash()
            ->submit('Test', 'A sta.sh test', null, null,true)
            ->addPart(ApiRequestPart::from('test', fopen('/home/bizzl/test.txt', 'r'), 'test.txt'))
            ->send();
} catch (ApiException $e) {
    // Handle API exception
}

FAQ

  • Where are the curated endpoints? They are deprecated and you should not use them.
  • Why do so many endpoints have an $includeMature parameter? They are in the Docs. I know that they seem senseless and probably won't work, but they also don't really hurt.
  • All but one endpoint return \stdClass. Why? It's easier to type hint, and I don't need hydrators and entities. The library is after all basic and only thinly object-oriented. Maybe I'll write a more OOP library around this some day.

benkle/deviantart 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-21