Home > Backend Development > PHP Tutorial > Teach you step by step how to use PHP to connect to Baidu video content review interface

Teach you step by step how to use PHP to connect to Baidu video content review interface

WBOY
Release: 2023-08-12 14:22:01
Original
1666 people have browsed it

Teach you step by step how to use PHP to connect to Baidu video content review interface

Teach you step by step how to use PHP to interface with Baidu video content review interface

Introduction:
With the development of the Internet, a large amount of video content has been uploaded to major platforms superior. However, there are many videos with illegal information, vulgar violence and other bad information. In order to protect the legitimate rights and interests of users, major platforms are strengthening the review of video content. Baidu provides a powerful video content review interface that can effectively help us review video content. This article will take you step by step to use PHP language to connect to Baidu video content review interface.

Step 1: Apply for Baidu Video Content Review Interface

  1. First, we need to register an account on the Baidu AI open platform and create a new application.
  2. In the process of creating an application, choose to activate the "Content Review" service.
  3. After successful creation, you will get an API Key and Secret Key. These are the keys necessary to call the Baidu video content review interface.

Step 2: Install PHP SDK

  1. Download the PHP SDK provided by Baidu AI Open Platform and extract it to your project directory.
  2. In the project directory, create a config.php file to store your API Key and Secret Key. Add the following code in the file:
<?php

// 替换为自己的API Key和Secret Key
define('API_KEY', 'your_api_key');
define('SECRET_KEY', 'your_secret_key');
Copy after login
  1. In the PHP file that needs to use the Baidu video content review interface, introduce the SDK file and load the configuration. The sample code is as follows:
<?php

require_once 'AipContentCensor/AipContentCensor.php';
require_once 'config.php';

// 创建SDK对象
$client = new AipContentCensor(API_KEY, SECRET_KEY);
Copy after login

Step 3: Call the video review interface
Now, we can start using the Baidu video content review interface for video review.

  1. Create a new PHP file in the directory where the video file that needs to be reviewed is located. The sample code is as follows:
<?php

require_once 'path_to_sdk/AipContentCensor/AipContentCensor.php';
require_once 'config.php';

// 创建SDK对象
$client = new AipContentCensor(API_KEY, SECRET_KEY);

// 视频审核
$response = $client->videoCensorUserDefined('path_to_video_file');

// 输出审核结果
var_dump($response);
Copy after login

In the code, we use The videoCensorUserDefined method reviews the video. You need to replace path_to_sdk with your SDK path and path_to_video_file with the video file path that needs to be reviewed.

  1. Run the PHP file and you will get a JSON string of the audit results. You can determine whether the video violates the rules based on the fields in the results.

Code example:

Array
(
    [conclusion] => 不合规
    [log_id] => 2021081800000001
    [data] => Array
        (
            [0] => Array
                (
                    [subType] => ocr 抽样检查
                    [conclusion] => 不合规
                    [msg] => 【抽样检查】文字色情信息
                )

            [1] => Array
                (
                    [subType] => porn 色情
                    [conclusion] => 不合规
                    [msg] => 【Porn】【色情】
                )

        )
)
Copy after login

In the above example, the conclusion field represents the review result of the video. The log_id field is the log ID of this audit. The array in the data field represents the non-compliance type, audit conclusion and audit information.

Summary:
Through the above steps, we successfully used PHP to connect to the Baidu video content review interface and implemented the function of reviewing videos. I hope this article can help you strengthen the review of video content and protect the legitimate rights and interests of users.

The above is the detailed content of Teach you step by step how to use PHP to connect to Baidu video content review interface. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template