概述

二维码 API 是 HTTP API,可用于以编程方式创建自定义二维码。每个二维码都将包含一个唯一的 Branch Link,您可以使用该 Branch Link 进行深度链接和追踪分析。

📘

QR Code API

Access to Branch's QR Code API and SDK requires premium product access. Please reach out to your account manager or https://branch.io/pricing/ to activate.

创建二维码

Endpoint

POST /v1/qr-code
Content-Type: application/json

频率限制

  • 每秒 25 个请求
  • 每分钟 100 个请求
  • 每小时 1000 个请求

参数

参数

类型

定义

branch_key(必填

String

The Branch key of the originating app; from your Branch Settings Dashboard

data(可选

JSON

The dictionary to embed link data behind the QR Code. Accessed as session or install parameters from the SDK. Use the data dictionary for all link control parameters that you'll find here.

Branch analytics parameters (Optional)

String

请确保使用分析标签的组织结构标签链接,以使数据在操作后台 (Dashboard)中显示一致且易读。

qr_code_settings

JSON

如果不存在任何键/值对,则我们将使用您的 App 默认设置。有关设置的详细信息,请参见下表。

qr_code_settings

参数

类型

定义

code_color

String

Hex color value of the QR Code itself.

background_color

String

二维码本身背景的十六进制颜色值。

边距

整数(像素)

The number of pixels you want for the margin. Min 1px. Max 20px.

宽度

整数(像素)

Output size of QR Code image. Min 300px. Max 2000px. (Only applicable to JPEG/PNG)

image_format

String

“JPEG”, “PNG”

center_logo_url

String (HTTP URL)

URL to the image you want as a center logo e.g. “https://cdn.branch.io/branch-assets/1598575682753-og_image.png”

样品申请

curl -X POST \
  https://api2.branch.io/v1/qr-code \
  -d '{
  "campaign": "qr_campaign",
  "channel": "flyer_1",
  "feature": "qr_codes",
  "data": {
    "$canonical_identifier": "content/123",
    "$og_title": "Title from Deep Link",
    "$og_description": "Description for QR code",
    "$og_image_url": "http://www.lorempixel.com/400/400/",
    "$canonical_url": "http://www.example.com/content/123",
    "custom_string": "anything"
  },
  "qr_code_settings": {
    "center_logo_url": "https://cdn.branch.io/branch-assets/1598575682753-og_image.png",
    "image_format": "png",
    "width": 512
  },
  "branch_key": "XXXXX_BRANCH_KEY_GOES_HERE_XXXXX"
}' --output qr_code.png

📘

图像输出

Note that the output of this cURL requests will be saved in the current directory as the file name indicated at the end of the request e.g. qr_code.png

结果

512512