定制 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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固