Tweets
使用此端点获取有关 Mautic 推文的详细信息。
Note
“推文”功能是 Mautic for Social 插件的一部分。要使此 API 正常工作,必须启用与 Twitter 的集成。
使用 Mautic API 库
您可以使用以下 :xref:`Mautic API Library 与此 API 进行交互,或者使用本文档中描述的各种 HTTP 端点。
<?php
use Mautic\MauticApi;
use Mautic\Auth\ApiAuth;
// ...
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings);
$apiUrl = "https://example.com";
$api = new MauticApi();
$tweetApi = $api->newApi("tweets", $auth, $apiUrl);
获取推文
通过 ID 检索单个推文。
<?php
//...
$tweet = $tweetApi->get($id);
HTTP 请求
GET /tweets/ID
响应
当请求成功检索到推文时,返回
200 OK。
{
"tweet": {
"isPublished": true,
"dateAdded": "2026-02-03T17:51:58+00:00",
"dateModified": "2026-03-28T11:03:03+00:00",
"createdBy": 1,
"createdByUser": "John Doe",
"modifiedBy": 1,
"modifiedByUser": "John Doe",
"id": 1,
"name": "Thank you tweet",
"text": "Hi {twitter_handle}\n\nThanks for ...",
"description": "Used in the Product A campaign 1",
"language": "en",
"category": {
"createdByUser": "John Doe",
"modifiedByUser": null,
"id": 185,
"title": "Thank you tweets",
"alias": "thank-you-tweets",
"description": null,
"color": "244bc9",
"bundle": "global"
},
"mediaId": null,
"mediaPath": null,
"sentCount": 3,
"favoriteCount": 0,
"retweetCount": 0
}
}
推文属性
- Name
Type
Description
idinteger
ID of the Tweet
namestring
Title of the Tweet
textstring
Message content of the Tweet. Maximum 280 characters.
descriptionstring
Internal description for the Tweet
isPublishedboolean
Tweet publication status
publishUpdatetime
Activation date and time for the Tweet
publishDowndatetime
Deactivation date and time for the Tweet
dateAddeddatetime
Tweet record creation date and time
createdByinteger
ID of the User who created the Tweet
createdByUserstring
Name of the User who created the Tweet
dateModifieddatetime
Tweet record last modification date and time
modifiedByinteger
ID of the User who last modified the Tweet
modifiedByUserstring
Name of the User who last modified the Tweet
languagestring
The language code for the Tweet, such as
en,fr, and so on
categoryobject
The Category for the Tweet
mediaIdstring
ID of the Twitter media object attached to the Tweet
mediaPathstring
Path to the local media file
sentCountinteger
Number of times this Tweet has been sent
favoriteCountinteger
Number of favorites or likes on the Tweet
retweetCountinteger
Number of retweets
List Tweets
Retrieves a list of Tweets.
<?php
// ...
$tweets = $tweetApi->getList($searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal);
HTTP request
GET /tweets
Query parameters
Name |
Type |
Description |
|---|---|---|
|
string |
String or search command to filter entities |
|
integer |
Starting row for the returned entities - defaults to 0 |
|
integer |
Maximum number of entities to return - defaults to 30 |
|
string |
Column to sort by. Any column in the response is valid. Note: convert |
|
string |
Order direction - |
|
boolean |
Returns only currently published entities |
|
boolean |
Returns only a simple mapped object of entities without additional lists in it |
Response
当请求成功检索到推文列表时,返回
200 OK。
{
"total": 1,
"tweets": [
{
"isPublished": true,
"dateAdded": "2026-02-03T17:51:58+00:00",
"dateModified": "2026-03-28T11:03:03+00:00",
"createdBy": 1,
"createdByUser": "John Doe",
"modifiedBy": 1,
"modifiedByUser": "John Doe",
"id": 1,
"name": "Thank you tweet",
"text": "Hi {twitter_handle}\n\nThanks for ...",
"description": "Used in the Product A campaign 1",
"language": "en",
"category": null,
"mediaId": null,
"mediaPath": null,
"sentCount": 3,
"favoriteCount": 0,
"retweetCount": 0
}
]
}
Properties
Name |
Type |
Description |
|---|---|---|
|
integer |
推文的总数。 |
|
array |
推文对象的数组。 |
对于其他属性,请参考 推文属性。
创建推文
创建一个新的推文。
<?php
$data = [
'name' => 'Tweet A',
'text' => 'This is my first tweet created via API.',
];
$tweet = $tweetApi->create($data);
HTTP 请求
POST /tweets/new
POST 参数
Name |
Type |
Description |
|---|---|---|
|
string |
推文的标题。 必填。 |
|
string |
推文的消息内容。 最多 280 个字符。 必填。 |
|
string |
推文的内部描述。 |
|
boolean |
推文的发布状态。 |
|
datetime |
推文的激活日期和时间。 |
|
datetime |
推文的停用日期和时间。 |
|
string |
推文的语言代码,例如 |
|
integer |
推文所属类别的 ID。 |
|
integer |
与推文关联的资源的 ID。 |
|
integer |
与推文关联的页面的 ID。 |
响应
当请求成功创建推文时,返回
201 Created。
响应是一个类似于 获取推文 的 JSON 对象。
Properties
请参考 推文属性。
编辑推文
编辑一个推文。
此操作支持 PUT 或 PATCH,具体取决于所需的行为:
PUT: 完全替换。如果 ID 不存在,则请求会创建一个新的推文。如果 ID 已存在,则请求会清除所有现有数据并用提供的值进行替换。PATCH: 部分更新。该请求仅根据请求数据更新字段值。当推文 ID 不存在时,请求将失败。
<?php
$id = 1;
$data = [
'name' => 'Tweet A',
'text' => 'This is my first tweet created via API.',
];
// 如果 ID 1 未找到,则创建新的推文
$createIfNotFound = true;
$tweet = $tweetApi->edit($id, $data, $createIfNotFound);
HTTP 请求
PUT /tweets/ID/edit: 更新现有的推文,或者当 ID 不存在时创建一个新的推文。PATCH /tweets/ID/edit: 更新现有的推文。当 ID 不存在时,请求将失败。
POST 参数
接受与 创建推文 中描述的相同参数。所有参数都是可选的。
响应
PUT: 当请求成功更新推文时返回200 OK,或者当请求创建推文时返回201 Created。PATCH: 当请求成功更新推文时返回200 OK,或者当推文 ID 不存在时返回404 Not Found错误。
响应是一个类似于 获取推文 的 JSON 对象。
属性
请参阅 推文属性.
删除推文
删除一个推文。
<?php
$tweet = $tweetApi->delete($id);
HTTP 请求
DELETE /tweets/ID/delete
响应
当请求成功删除推文时,返回
200 OK。
响应是一个包含已删除推文数据的 JSON 对象,类似于 获取推文。
属性
请参阅 推文属性.