Download the PHP package jiangwang/ad-ocean-sdk without Composer

On this page you can find all versions of the php package jiangwang/ad-ocean-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ad-ocean-sdk

巨量引擎 PHP SDK

Latest Version PHP Version License

一个用于巨量引擎(OceanEngine)开放 API 的 PHP SDK。

功能特性

环境要求

安装

使用 Composer 安装:

快速开始

基本使用

使用对象参数调用 API

除了数组参数外,也可以使用参数对象调用 API,这样可以获得更好的类型安全和 IDE 自动补全:

说明:

配置化初始化

可配置能力总览

SdkConfig 用来在初始化阶段装配默认 RequestClient;初始化完成后,你仍然可以通过 $app->client() 在运行时继续调整大多数配置。

类别 入口 作用
基础网络 setDomain() / setTimeout() 设置默认域名与默认超时
鉴权与请求头 setAccessToken() / setHeaders() / addHeader() 设置全局 Access-Token 与公共 header
Guzzle 接管 setHttpClient() / setHttpClientOptions() 注入现成 Client,或透传底层构造选项
错误处理 setThrowOnApiError() 将业务返回码转成异常,并区分鉴权/限流异常
重试策略 setRetryPolicy() 对网络异常与限流异常做指数退避重试
OAuth 刷新 setOAuthTokenProvider() 鉴权失败后自动刷新 token 并重试一次
中间件扩展 addMiddleware() 在初始化时把自定义 middleware 挂入默认 pipeline
日志 setLogger() 注入 PSR-3 logger,记录请求发送/完成/失败日志

一份完整配置示例

说明:

注入自定义 RequestClient

如果你希望完全掌控 HTTP 行为,可以自己实现 RequestClientInterface,或者直接继承默认 RequestClient:

Application::init() 现在接收 RequestClientInterface,因此可以安全注入自定义 client 实现。

注入自定义 Guzzle Client

如果你只想接管底层 Guzzle 能力,而不重写整个 RequestClient,推荐这样做:

说明:

例如,仅透传 Guzzle 构造参数而不自己 new Client:

运行时调整 RequestClient

初始化完成后,可以直接操作 $app->client():

如果你在常驻进程或多租户环境中运行,推荐把 token 注入逻辑放进 middleware,而不是在共享 client 上频繁切换全局 token。

Middleware 中间件

说明:

如果你需要精确控制插入位置,可以直接操作 pipeline:

说明:

多账号场景:按参数动态注入 Token

如果你像业务项目里那样,需要根据不同用户或不同 advertiser_id 注入不同 token,推荐使用中间件,而不是在共享 client 上频繁切换全局 token。

这种方式的好处是:

内置中间件能力

SdkConfig 提供了几种常用的内置 middleware 装配入口:

1. 业务错误抛出:setThrowOnApiError()

说明:

2. 重试策略:setRetryPolicy()

说明:

3. OAuth 自动刷新:setOAuthTokenProvider()

说明:

4. 日志:setLogger()

说明:

异步与批量调用

说明:

直接 HTTP 请求

当你还没有生成 RequestApi 类,但又希望继续复用 SDK 的 middleware、token 注入、重试、异常包装与响应解码时,可以直接使用 RequestClient 的 HTTP 入口。

说明:

自定义API

如果需要调用新的API或自定义API,可以继承基础类:

建议:

异常说明

常见异常包括:

建议在业务项目中统一捕获 SDK 异常并转成你的应用层错误。

测试

贡献指南

欢迎提交Issue和Pull Request来改善这个项目。

  1. Fork 项目
  2. 创建特性分支 (git checkout -b feature/amazing-feature)
  3. 提交改动 (git commit -m 'Add amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 创建 Pull Request

许可证

本项目使用 MIT 许可证。详情请参阅 LICENSE 文件。

相关链接


All versions of ad-ocean-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
guzzlehttp/guzzle Version ^7.5.0
psr/log Version ^1.1 || ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jiangwang/ad-ocean-sdk contains the following files

Loading the files please wait ...