
本文以Python、Java、Go三种语言为例,提供腾讯云IMS图片审核API的完整接入代码与调试技巧,助开发者30分钟内完成首次图片审核。
📌 腾讯云图片内容安全产品介绍: https://cloud.tencent.com/product/ims
🔥 限时特惠活动(产品首单5折起): https://cloud.tencent.com/act/pro/moltbotandai#nrsb
项目 | 值 |
|---|---|
API域名 |
|
核心接口 |
|
协议 | 支持HTTP和HTTPS |
图片传入方式 | URL(FileUrl)或 Base64(FileContent) |
pip install tencentcloud-sdk-pythonimport json
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.ims.v20201229 import ims_client, models
def image_moderation(image_url):
try:
# 1. 配置密钥
cred = credential.Credential("你的SecretId", "你的SecretKey")
# 2. 创建客户端
client = ims_client.ImsClient(cred, "ap-guangzhou")
# 3. 构建请求
req = models.ImageModerationRequest()
req.FileUrl = image_url
# req.BizType = "你的Biztype" # 使用自定义策略时传入
# 4. 发送请求
resp = client.ImageModeration(req)
# 5. 解析结果
result = json.loads(resp.to_json_string())
print(f"建议操作: {result['Suggestion']}")
print(f"风险标签: {result['Label']}")
return result
except TencentCloudSDKException as err:
print(f"错误: {err}")
return None
# 调用示例
image_moderation("https://example.com/test-image.jpg")<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>最新版本</version>
</dependency>import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.ims.v20201229.ImsClient;
import com.tencentcloudapi.ims.v20201229.models.*;
public class ImageModerationDemo {
public static void main(String[] args) {
try {
// 1. 配置密钥
Credential cred = new Credential("你的SecretId", "你的SecretKey");
// 2. 创建客户端
ImsClient client = new ImsClient(cred, "ap-guangzhou");
// 3. 构建请求
ImageModerationRequest req = new ImageModerationRequest();
req.setFileUrl("https://example.com/test-image.jpg");
// 4. 发送请求
ImageModerationResponse resp = client.ImageModeration(req);
// 5. 解析结果
System.out.println("建议操作: " + resp.getSuggestion());
System.out.println("风险标签: " + resp.getLabel());
} catch (Exception e) {
e.printStackTrace();
}
}
}go get -v github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/imspackage main
import (
"fmt"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
ims "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ims/v20201229"
)
func main() {
// 1. 配置密钥
credential := common.NewCredential("你的SecretId", "你的SecretKey")
cpf := profile.NewClientProfile()
// 2. 创建客户端
client, _ := ims.NewClient(credential, "ap-guangzhou", cpf)
// 3. 构建请求
request := ims.NewImageModerationRequest()
url := "https://example.com/test-image.jpg"
request.FileUrl = &url
// 4. 发送请求
response, err := client.ImageModeration(request)
if err != nil {
fmt.Printf("错误: %s\n", err)
return
}
// 5. 解析结果
fmt.Printf("建议操作: %s\n", *response.Response.Suggestion)
fmt.Printf("风险标签: %s\n", *response.Response.Label)
}技巧 | 说明 |
|---|---|
用API Explorer调试 | 腾讯云提供在线API调试工具,填参数即可测试 |
超时设置 | 建议连接超时10s,读取超时30s |
错误码处理 | 常见错误:RequestLimitExceeded(QPS超限)、ImageDownloadError(图片下载失败) |
图片URL要求 | 必须包含http/https协议头,外网可访问 |
Base64注意 | 总请求体不超过10MB |
套餐类型 | 条件限制 | 规格 | 有效期 | 特惠价格 |
|---|---|---|---|---|
🔥 180万张套餐包 | 产品首单 | 180万张 | 1年 | 2,000元(5折) |
🔥 180万张套餐包 | 新老同享 | 180万张 | 1年 | 3,400元(8.5折) |
🔥 720万张套餐包 | 新老同享 | 720万张 | 1年 | 11,900元(8.5折) |
📌 立即体验腾讯云图片内容安全: https://cloud.tencent.com/product/ims
🔥 限时特惠活动进行中(首单5折): https://cloud.tencent.com/act/pro/moltbotandai#nrsb
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。