官方 Agilis Advertising SDK
支持七种语言的库。每个库都涵盖所有端点,从 AGILIS_API_KEY 读取您的密钥,安全地重试,对任何返回代码抛出错误,并验证 webhook 签名。
| 语言 | 软件包 | 安装 | 运行要求 | 源代码与更新日志 |
|---|---|---|---|---|
| Node.js and TypeScript | @agilisdating/ads (npm) |
npm install @agilisdating/ads |
Node.js 20 or later | 源代码 · 更新日志 |
| Python | agilis-ads (PyPI) |
pip install agilis-ads |
Python 3.10 or later | 源代码 · 更新日志 |
| PHP | agilisdating/agilis-ads (Packagist) |
composer require agilisdating/agilis-ads guzzlehttp/guzzle |
PHP 8.2 or later, with any PSR-18 HTTP client (Guzzle suggested) | 源代码 · 更新日志 |
| .NET (C#) | Agilis.Ads (NuGet) |
dotnet add package Agilis.Ads |
.NET 8 or later, or .NET Standard 2.0; usable from Visual Basic too | 源代码 · 更新日志 |
| Java | dating.agilis:agilis-ads (Maven Central) |
implementation("dating.agilis:agilis-ads:0.1.0") Gradle (Kotlin). With Maven: groupId dating.agilis, artifactId agilis-ads, version 0.1.0. |
Java 17 or later | 源代码 · 更新日志 |
| Go | github.com/agilisdating/agilis-ads-go (pkg.go.dev) |
go get github.com/agilisdating/agilis-ads-go |
Go 1.22 or later | 源代码 · 更新日志 |
| Ruby | agilis-ads (RubyGems) |
gem install agilis-ads |
Ruby 3.2 or later | 源代码 · 更新日志 |
您的第一个请求
使用测试密钥列出优惠类别。每个示例都与 API 参考文档出自同一来源。
Node.js and TypeScript
import { Agilis } from '@agilisdating/ads';
const client = new Agilis(); // reads AGILIS_API_KEY
const result = await client.categories.list();
console.log(result.categories?.length);Python
from agilis_ads import Agilis client = Agilis() # reads AGILIS_API_KEY result = client.categories.list() print(len(result["categories"]))
PHP
<?php require 'vendor/autoload.php'; use Agilis\Ads\AgilisClient; $agilis = new AgilisClient(); // reads AGILIS_API_KEY $result = $agilis->categories->list(); echo count($result['categories']), "\n";
.NET (C#)
using Agilis.Ads; using var client = new AgilisClient(); // reads AGILIS_API_KEY var result = await client.Categories.ListAsync(); Console.WriteLine(result.Categories.Count);
Java
import dating.agilis.ads.AgilisClient; AgilisClient client = AgilisClient.builder().build(); // reads AGILIS_API_KEY var result = client.categories().list(); System.out.println(result.getCategories().size());
Go
package main
import (
"context"
"fmt"
"log"
agilisads "github.com/agilisdating/agilis-ads-go"
)
func main() {
client := agilisads.NewClient("") // reads AGILIS_API_KEY
ctx := context.Background()
result, err := client.Categories.List(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(len(result.Categories))
}Ruby
require "agilis_ads" client = AgilisAds::Client.new # reads AGILIS_API_KEY result = client.categories.list puts result.categories.length
验证 webhook
每个 SDK 只需一次调用,即可根据您端点的密钥校验 Agilis-Signature 标头。请使用未经任何解析的原始请求正文。
Node.js and TypeScript
import { webhooks } from '@agilisdating/ads';
const event = webhooks.constructEvent(rawBody, signatureHeader, secret);Python
from agilis_ads import construct_event event = construct_event(raw_body, signature_header, secret)
PHP
use Agilis\Ads\Webhooks; $event = (new Webhooks())->constructEvent($rawBody, $signatureHeader, $secret);
.NET (C#)
using Agilis.Ads; var webhookEvent = Webhooks.ConstructEvent(rawBody, signatureHeader, secret);
Java
import dating.agilis.ads.Webhooks; var event = Webhooks.constructEvent(rawBody, signatureHeader, secret);
Go
import agilisads "github.com/agilisdating/agilis-ads-go" event, err := agilisads.ConstructEvent(payload, signatureHeader, secret)
Ruby
require "agilis_ads" event = AgilisAds::Webhook.construct_event(raw_body, signature_header, secret)
故障排除
- 密钥未被接受:请检查密钥及其模式;测试密钥仅在测试模式下有效。
- 返回 HTTP 200 的错误:SDK 会连同返回码一起抛出该错误(例如 E3,余额不足)。
- 请求过多:SDK 会等待并重试;请将每个密钥的请求量控制在每分钟 60 次以内。
- 位于公司代理之后:某些网络会检查安全连接;请将
ads.agilis.dating加入允许列表。 - 图片被拒绝:图片在发布前会经过审核;请选择其他图片。
