curl \
-H "Authorization: Bearer API_KEY" \
-X GET https://api.ayrshare.com/api/messages/facebook
const apiKey = 'API_KEY';
const url = 'https://api.ayrshare.com/api/messages/facebook';
const headers = {
'Authorization': `Bearer ${apiKey}`,
};
fetch(url, {
method: 'GET',
headers: headers,
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error(`Request failed. Status code: ${response.status}`);
}
})
.then(data => {
console.log('Response:', data);
})
.catch(error => {
console.error('Error:', error.message);
});
import requests
api_key = 'API_KEY'
url = 'https://api.ayrshare.com/api/messages/facebook'
headers = {
'Authorization': f'Bearer {api_key}',
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print('Response:', data)
else:
print(f'Request failed. Status code: {response.status_code}')
<?php
$apiKey = 'API_KEY';
$url = 'https://api.ayrshare.com/api/messages/facebook';
$headers = [
'Authorization: Bearer ' . $apiKey,
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
echo 'Error: ' . $error;
} else {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode === 200) {
$responseData = json_decode($response, true);
print_r($responseData);
} else {
echo 'Request failed. Status code: ' . $statusCode;
}
}
curl_close($ch);
?>
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Text.Json;
class Program
{
static async Task Main()
{
string apiKey = "API_KEY";
string url = "https://api.ayrshare.com/api/messages/facebook";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
try
{
var response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
var responseData = JsonSerializer.Deserialize<dynamic>(responseBody);
Console.WriteLine("Response:");
Console.WriteLine(responseData);
}
else
{
Console.WriteLine($"Request failed. Status code: {response.StatusCode}");
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) {
String apiKey = "API_KEY";
String url = "https://api.ayrshare.com/api/messages/facebook";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.GET()
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
String responseBody = response.body();
System.out.println("Response:");
System.out.println(responseBody);
} else {
System.out.println("Request failed. Status code: " + response.statusCode());
}
} catch (IOException | InterruptedException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
{
"status": "success",
"messages": [
{
"senderId": "106638148652444",
"senderDetails": {
"name": "Ayrshare"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:54:32.455Z",
"action": "sent",
"recipientId": "7101149746568444",
"id": "m_JH6o-yS83JoxWmQaLrmgSaHwGtfTgQ",
"message": "Howdy!",
"platform": "facebook",
"reactions": {
"7101149746568522": "😆". // 客戶對 Howdy! 訊息的反應
}
},
{
"recipientDetails": {
"name": "Sara Smith",
"id": "736532028017333",
"picture": "https://img.ayrshare.com/333/messages/facebook-eTZzhE2b.jpeg"
},
"senderId": "106638148652329",
"attachments": [
{
"type": "image",
"url": "https://scontent.xx.fbcdn.net/v/t1.15752-9/490986808_1193328359195158"
}
],
"conversationId": "t_3567590438533",
"created": "2024-06-06T00:54:32.455Z",
"action": "sent",
"recipientId": "736532028017333",
"id": "m_WJlfgzopxfdRM1wFTKYHKv7zh75P",
"updated": "2024-06-06T00:54:32.455Z",
"platform": "facebook",
"senderDetails": {
"name": "Ayrshare"
}
},
{
"senderId": "7101149746568444",
"senderDetails": {
"name": "John Smith",
"profileImage": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:54:28.102Z",
"action": "received",
"recipientId": "106638148652329",
"id": "m_HGbotYJUmf4AzyPlJ-2uZqHwGtfTgQihX",
"message": "Look up!",
"platform": "facebook"
},
{
"senderId": "7101149746568444",
"senderDetails": {
"name": "John Smith",
"profileImage": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:49:11.679Z",
"action": "received",
"recipientId": "106638148652444",
"id": "m_jXoYQIwTXaq2u06PG6Z8vaHwGtfTgQ",
"message": "How is the weather?",
"platform": "facebook"
}
],
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:47:04.233Z"
}
{
"status": "success",
"messages": [
{
"id": "1893410668991234567",
"conversationId": "1234567890-9876543210",
"senderId": "9876543210",
"created": "2024-06-09T21:30:00.000Z",
"message": "Hey, how are you?",
"action": "received",
"senderDetails": {
"name": "Jane Doe",
"username": "janedoe"
}
},
{
"id": "1893410668991234566",
"conversationId": "1234567890-9876543210",
"senderId": "1234567890",
"created": "2024-06-09T21:28:00.000Z",
"message": "Hello!",
"action": "sent",
"senderDetails": {
"name": "My Account",
"username": "myaccount"
}
}
],
"messagesCount": 2,
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:46:19.233Z",
"meta": {
"pagination": {
"hasMore": true,
"limit": 5,
"next": "eyJwYWdpbmF0aW9uVG9rZW4iOiIxODkzNDEwNjY4OTkxMjM0NTY1In0="
}
}
}
{
"status": "success",
"conversationIds": ["t_10161117434308444", "t_356759043857444"],
"conversationsDetails": [
{
"id": "t_10161117434308444",
"participant": {
"name": "John Smith",
"id": "7101149746568444",
"picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"status": "active",
"watermark": 1717889607444
},
{
"id": "t_356759043857444",
"participant": {
"name": "Sara Johnson",
"id": "7365320280173444",
"picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"status": "active"
}
],
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:47:04.233Z"
}
{
"action": "messages",
"status": "error",
"code": 361,
"message": "Messaging is not enabled for this User Profile. Please subscribe to Messaging and activate Messaging for this User Profile."
}
Messages
取得訊息
取得訊息平台上的訊息或對話
GET
/
messages
/
:platform
curl \
-H "Authorization: Bearer API_KEY" \
-X GET https://api.ayrshare.com/api/messages/facebook
const apiKey = 'API_KEY';
const url = 'https://api.ayrshare.com/api/messages/facebook';
const headers = {
'Authorization': `Bearer ${apiKey}`,
};
fetch(url, {
method: 'GET',
headers: headers,
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error(`Request failed. Status code: ${response.status}`);
}
})
.then(data => {
console.log('Response:', data);
})
.catch(error => {
console.error('Error:', error.message);
});
import requests
api_key = 'API_KEY'
url = 'https://api.ayrshare.com/api/messages/facebook'
headers = {
'Authorization': f'Bearer {api_key}',
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print('Response:', data)
else:
print(f'Request failed. Status code: {response.status_code}')
<?php
$apiKey = 'API_KEY';
$url = 'https://api.ayrshare.com/api/messages/facebook';
$headers = [
'Authorization: Bearer ' . $apiKey,
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
echo 'Error: ' . $error;
} else {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode === 200) {
$responseData = json_decode($response, true);
print_r($responseData);
} else {
echo 'Request failed. Status code: ' . $statusCode;
}
}
curl_close($ch);
?>
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Text.Json;
class Program
{
static async Task Main()
{
string apiKey = "API_KEY";
string url = "https://api.ayrshare.com/api/messages/facebook";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
try
{
var response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
var responseData = JsonSerializer.Deserialize<dynamic>(responseBody);
Console.WriteLine("Response:");
Console.WriteLine(responseData);
}
else
{
Console.WriteLine($"Request failed. Status code: {response.StatusCode}");
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) {
String apiKey = "API_KEY";
String url = "https://api.ayrshare.com/api/messages/facebook";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.GET()
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
String responseBody = response.body();
System.out.println("Response:");
System.out.println(responseBody);
} else {
System.out.println("Request failed. Status code: " + response.statusCode());
}
} catch (IOException | InterruptedException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
{
"status": "success",
"messages": [
{
"senderId": "106638148652444",
"senderDetails": {
"name": "Ayrshare"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:54:32.455Z",
"action": "sent",
"recipientId": "7101149746568444",
"id": "m_JH6o-yS83JoxWmQaLrmgSaHwGtfTgQ",
"message": "Howdy!",
"platform": "facebook",
"reactions": {
"7101149746568522": "😆". // 客戶對 Howdy! 訊息的反應
}
},
{
"recipientDetails": {
"name": "Sara Smith",
"id": "736532028017333",
"picture": "https://img.ayrshare.com/333/messages/facebook-eTZzhE2b.jpeg"
},
"senderId": "106638148652329",
"attachments": [
{
"type": "image",
"url": "https://scontent.xx.fbcdn.net/v/t1.15752-9/490986808_1193328359195158"
}
],
"conversationId": "t_3567590438533",
"created": "2024-06-06T00:54:32.455Z",
"action": "sent",
"recipientId": "736532028017333",
"id": "m_WJlfgzopxfdRM1wFTKYHKv7zh75P",
"updated": "2024-06-06T00:54:32.455Z",
"platform": "facebook",
"senderDetails": {
"name": "Ayrshare"
}
},
{
"senderId": "7101149746568444",
"senderDetails": {
"name": "John Smith",
"profileImage": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:54:28.102Z",
"action": "received",
"recipientId": "106638148652329",
"id": "m_HGbotYJUmf4AzyPlJ-2uZqHwGtfTgQihX",
"message": "Look up!",
"platform": "facebook"
},
{
"senderId": "7101149746568444",
"senderDetails": {
"name": "John Smith",
"profileImage": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:49:11.679Z",
"action": "received",
"recipientId": "106638148652444",
"id": "m_jXoYQIwTXaq2u06PG6Z8vaHwGtfTgQ",
"message": "How is the weather?",
"platform": "facebook"
}
],
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:47:04.233Z"
}
{
"status": "success",
"messages": [
{
"id": "1893410668991234567",
"conversationId": "1234567890-9876543210",
"senderId": "9876543210",
"created": "2024-06-09T21:30:00.000Z",
"message": "Hey, how are you?",
"action": "received",
"senderDetails": {
"name": "Jane Doe",
"username": "janedoe"
}
},
{
"id": "1893410668991234566",
"conversationId": "1234567890-9876543210",
"senderId": "1234567890",
"created": "2024-06-09T21:28:00.000Z",
"message": "Hello!",
"action": "sent",
"senderDetails": {
"name": "My Account",
"username": "myaccount"
}
}
],
"messagesCount": 2,
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:46:19.233Z",
"meta": {
"pagination": {
"hasMore": true,
"limit": 5,
"next": "eyJwYWdpbmF0aW9uVG9rZW4iOiIxODkzNDEwNjY4OTkxMjM0NTY1In0="
}
}
}
{
"status": "success",
"conversationIds": ["t_10161117434308444", "t_356759043857444"],
"conversationsDetails": [
{
"id": "t_10161117434308444",
"participant": {
"name": "John Smith",
"id": "7101149746568444",
"picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"status": "active",
"watermark": 1717889607444
},
{
"id": "t_356759043857444",
"participant": {
"name": "Sara Johnson",
"id": "7365320280173444",
"picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"status": "active"
}
],
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:47:04.233Z"
}
{
"action": "messages",
"status": "error",
"code": 361,
"message": "Messaging is not enabled for this User Profile. Please subscribe to Messaging and activate Messaging for this User Profile."
}
取得訊息平台上的訊息或對話。
各社群網路的擷取時效不同。在 Facebook 與 Instagram 上,訊息可透過 Ayrshare 即時取得。在 X/Twitter 上,看到新訊息更新最多會有 3 分鐘的延遲。若您需要 X/Twitter 訊息的即時存取,請聯絡我們了解 Enterprise Plan 的更多資訊。
回應快取: GET 訊息的回應會被快取以最佳化效能。Facebook 與 Instagram 的回應會快取 60 秒。X/Twitter 的回應會快取 15 秒,以便更好地支援輪詢 (polling)。回應中的
lastUpdated 與 nextUpdate 欄位會指出資料最後擷取的時間,以及下次可以取得新資料的時間。Facebook 與 Instagram 的初始訊息歷程擷取上限為
最後 20 則訊息。詳細資訊請參閱 Facebook 與 Instagram 的訊息歷程擷取章節。
標頭參數
路徑參數
用來取得訊息的平台:
facebook、instagram、twitter查詢參數
回傳活躍或已封存的對話。值:
active 或
archived。只回傳特定對話。
回傳所有對話。若為
true,則忽略 conversationId 欄位。僅 X/Twitter。 限制每次請求回傳的訊息數 (1–100)。可有效輪詢而不需完整同步歷史資料。與
next 搭配使用以進行分頁。若省略,則使用預設行為(完整訊息擷取)。僅 X/Twitter。 從前一次請求
meta.pagination.next 欄位取得的加密分頁游標。與 limit 搭配使用以擷取下一頁結果。curl \
-H "Authorization: Bearer API_KEY" \
-X GET https://api.ayrshare.com/api/messages/facebook
const apiKey = 'API_KEY';
const url = 'https://api.ayrshare.com/api/messages/facebook';
const headers = {
'Authorization': `Bearer ${apiKey}`,
};
fetch(url, {
method: 'GET',
headers: headers,
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error(`Request failed. Status code: ${response.status}`);
}
})
.then(data => {
console.log('Response:', data);
})
.catch(error => {
console.error('Error:', error.message);
});
import requests
api_key = 'API_KEY'
url = 'https://api.ayrshare.com/api/messages/facebook'
headers = {
'Authorization': f'Bearer {api_key}',
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print('Response:', data)
else:
print(f'Request failed. Status code: {response.status_code}')
<?php
$apiKey = 'API_KEY';
$url = 'https://api.ayrshare.com/api/messages/facebook';
$headers = [
'Authorization: Bearer ' . $apiKey,
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
echo 'Error: ' . $error;
} else {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode === 200) {
$responseData = json_decode($response, true);
print_r($responseData);
} else {
echo 'Request failed. Status code: ' . $statusCode;
}
}
curl_close($ch);
?>
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Text.Json;
class Program
{
static async Task Main()
{
string apiKey = "API_KEY";
string url = "https://api.ayrshare.com/api/messages/facebook";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
try
{
var response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
var responseData = JsonSerializer.Deserialize<dynamic>(responseBody);
Console.WriteLine("Response:");
Console.WriteLine(responseData);
}
else
{
Console.WriteLine($"Request failed. Status code: {response.StatusCode}");
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) {
String apiKey = "API_KEY";
String url = "https://api.ayrshare.com/api/messages/facebook";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.GET()
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
String responseBody = response.body();
System.out.println("Response:");
System.out.println(responseBody);
} else {
System.out.println("Request failed. Status code: " + response.statusCode());
}
} catch (IOException | InterruptedException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
{
"status": "success",
"messages": [
{
"senderId": "106638148652444",
"senderDetails": {
"name": "Ayrshare"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:54:32.455Z",
"action": "sent",
"recipientId": "7101149746568444",
"id": "m_JH6o-yS83JoxWmQaLrmgSaHwGtfTgQ",
"message": "Howdy!",
"platform": "facebook",
"reactions": {
"7101149746568522": "😆". // 客戶對 Howdy! 訊息的反應
}
},
{
"recipientDetails": {
"name": "Sara Smith",
"id": "736532028017333",
"picture": "https://img.ayrshare.com/333/messages/facebook-eTZzhE2b.jpeg"
},
"senderId": "106638148652329",
"attachments": [
{
"type": "image",
"url": "https://scontent.xx.fbcdn.net/v/t1.15752-9/490986808_1193328359195158"
}
],
"conversationId": "t_3567590438533",
"created": "2024-06-06T00:54:32.455Z",
"action": "sent",
"recipientId": "736532028017333",
"id": "m_WJlfgzopxfdRM1wFTKYHKv7zh75P",
"updated": "2024-06-06T00:54:32.455Z",
"platform": "facebook",
"senderDetails": {
"name": "Ayrshare"
}
},
{
"senderId": "7101149746568444",
"senderDetails": {
"name": "John Smith",
"profileImage": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:54:28.102Z",
"action": "received",
"recipientId": "106638148652329",
"id": "m_HGbotYJUmf4AzyPlJ-2uZqHwGtfTgQihX",
"message": "Look up!",
"platform": "facebook"
},
{
"senderId": "7101149746568444",
"senderDetails": {
"name": "John Smith",
"profileImage": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"conversationId": "t_10161117434308444",
"created": "2024-06-06T00:49:11.679Z",
"action": "received",
"recipientId": "106638148652444",
"id": "m_jXoYQIwTXaq2u06PG6Z8vaHwGtfTgQ",
"message": "How is the weather?",
"platform": "facebook"
}
],
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:47:04.233Z"
}
{
"status": "success",
"messages": [
{
"id": "1893410668991234567",
"conversationId": "1234567890-9876543210",
"senderId": "9876543210",
"created": "2024-06-09T21:30:00.000Z",
"message": "Hey, how are you?",
"action": "received",
"senderDetails": {
"name": "Jane Doe",
"username": "janedoe"
}
},
{
"id": "1893410668991234566",
"conversationId": "1234567890-9876543210",
"senderId": "1234567890",
"created": "2024-06-09T21:28:00.000Z",
"message": "Hello!",
"action": "sent",
"senderDetails": {
"name": "My Account",
"username": "myaccount"
}
}
],
"messagesCount": 2,
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:46:19.233Z",
"meta": {
"pagination": {
"hasMore": true,
"limit": 5,
"next": "eyJwYWdpbmF0aW9uVG9rZW4iOiIxODkzNDEwNjY4OTkxMjM0NTY1In0="
}
}
}
{
"status": "success",
"conversationIds": ["t_10161117434308444", "t_356759043857444"],
"conversationsDetails": [
{
"id": "t_10161117434308444",
"participant": {
"name": "John Smith",
"id": "7101149746568444",
"picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"status": "active",
"watermark": 1717889607444
},
{
"id": "t_356759043857444",
"participant": {
"name": "Sara Johnson",
"id": "7365320280173444",
"picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/"
},
"status": "active"
}
],
"lastUpdated": "2024-06-09T21:46:04.233Z",
"nextUpdate": "2024-06-09T21:47:04.233Z"
}
{
"action": "messages",
"status": "error",
"code": 361,
"message": "Messaging is not enabled for this User Profile. Please subscribe to Messaging and activate Messaging for this User Profile."
}
⌘I
