curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"message": "What's up!", "recipientId": "283j839222"} \
-X POST https://api.ayrshare.com/api/messages/instagram
const apiKey = 'API_KEY';
const url = 'https://api.ayrshare.com/api/messages/instagram';
const data = {
message: "What's up!",
recipientId: '283j839222',
};
const headers = {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
};
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
console.log('Response:', data);
})
.catch(error => {
console.error('Error:', error);
});
import requests
api_key = 'API_KEY'
url = 'https://api.ayrshare.com/api/messages/instagram'
data = {
'message': "What's up!",
'recipientId': '283j839222',
}
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json',
}
response = requests.post(url, json=data, headers=headers)
print('Response:', response.json())
<?php
$apiKey = 'API_KEY';
$url = 'https://api.ayrshare.com/api/messages/instagram';
$data = [
'message' => "What's up!",
'recipientId' => '283j839222',
];
$headers = [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
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 {
$responseData = json_decode($response, true);
print_r($responseData);
}
curl_close($ch);
?>
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiKey = "API_KEY";
string url = "https://api.ayrshare.com/api/messages/instagram";
var data = new
{
message = "What's up!",
recipientId = "283j839222"
};
var jsonData = JsonSerializer.Serialize(data);
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
try
{
var response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var responseData = JsonSerializer.Deserialize<dynamic>(responseBody);
Console.WriteLine("Response:");
Console.WriteLine(responseData);
}
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/instagram";
String data = "{\"message\": \"What's up!\", \"recipientId\": \"283j839222\"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(data))
.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());
}
}
}
{ // tin nhắn văn bản đơn
"status": "success",
"recipientId": "72706337063589124",
"messageId": "aWdfZAG1faXRlbToxOkl",
"message": "What is up?"
}
{
// tin nhắn văn bản đơn
"action": "messages",
"status": "error",
"code": 363,
"message": "The recipient ID was not found. Please confirm the recipient ID is correct."
}
{
// hình ảnh đơn
"status": "success",
"recipientId": "761943",
"messageId": "m_EgvfBrgjaM",
"type": "image",
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg"
}
{
// tin nhắn văn bản và hình ảnh
"action": "send",
"status": "error",
"code": 337,
"message": "Error sending message.",
"messages": [
{
"recipientId": "727063370635",
"messageId": "aWdfZAG1faXRlbT",
"message": "What a great day"
},
{
"action": "messages",
"status": "error",
"code": 365,
"message": "An error occurred sending the message attachment. Please verify the attachment is still available and try again."
}
]
}
Messages
Gửi Tin nhắn
Gửi tin nhắn trực tiếp đến người nhận
POST
/
messages
/
:platform
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"message": "What's up!", "recipientId": "283j839222"} \
-X POST https://api.ayrshare.com/api/messages/instagram
const apiKey = 'API_KEY';
const url = 'https://api.ayrshare.com/api/messages/instagram';
const data = {
message: "What's up!",
recipientId: '283j839222',
};
const headers = {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
};
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
console.log('Response:', data);
})
.catch(error => {
console.error('Error:', error);
});
import requests
api_key = 'API_KEY'
url = 'https://api.ayrshare.com/api/messages/instagram'
data = {
'message': "What's up!",
'recipientId': '283j839222',
}
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json',
}
response = requests.post(url, json=data, headers=headers)
print('Response:', response.json())
<?php
$apiKey = 'API_KEY';
$url = 'https://api.ayrshare.com/api/messages/instagram';
$data = [
'message' => "What's up!",
'recipientId' => '283j839222',
];
$headers = [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
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 {
$responseData = json_decode($response, true);
print_r($responseData);
}
curl_close($ch);
?>
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiKey = "API_KEY";
string url = "https://api.ayrshare.com/api/messages/instagram";
var data = new
{
message = "What's up!",
recipientId = "283j839222"
};
var jsonData = JsonSerializer.Serialize(data);
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
try
{
var response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var responseData = JsonSerializer.Deserialize<dynamic>(responseBody);
Console.WriteLine("Response:");
Console.WriteLine(responseData);
}
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/instagram";
String data = "{\"message\": \"What's up!\", \"recipientId\": \"283j839222\"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(data))
.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());
}
}
}
{ // tin nhắn văn bản đơn
"status": "success",
"recipientId": "72706337063589124",
"messageId": "aWdfZAG1faXRlbToxOkl",
"message": "What is up?"
}
{
// tin nhắn văn bản đơn
"action": "messages",
"status": "error",
"code": 363,
"message": "The recipient ID was not found. Please confirm the recipient ID is correct."
}
{
// hình ảnh đơn
"status": "success",
"recipientId": "761943",
"messageId": "m_EgvfBrgjaM",
"type": "image",
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg"
}
{
// tin nhắn văn bản và hình ảnh
"action": "send",
"status": "error",
"code": 337,
"message": "Error sending message.",
"messages": [
{
"recipientId": "727063370635",
"messageId": "aWdfZAG1faXRlbT",
"message": "What a great day"
},
{
"action": "messages",
"status": "error",
"code": 365,
"message": "An error occurred sending the message attachment. Please verify the attachment is still available and try again."
}
]
}
Gửi một tin nhắn trực tiếp mới đến người nhận.
Định giá & Giới hạn: Mỗi User Profile có thể có tối đa 1.000 cuộc trò chuyện
đang hoạt động mỗi chu kỳ thanh toán trên tất cả các mạng xã hội. Định giá tùy thuộc
vào gói của bạn: Các gói Premium trả phí cố định 49mo^~ithaˊng∗∗nhưtiệnıˊchbổsung,trongkhicaˊcgoˊi∗∗Launch∗∗vaˋ∗∗Business∗∗đượctıˊnhphıˊ∗∗0,09 cho mỗi cuộc trò chuyện
đang hoạt động. Một cuộc trò chuyện được tính là
đang hoạt động khi bạn gửi tin nhắn cho người nhận trong chu kỳ thanh toán;
các tin nhắn đến một mình không được tính. Số lượng tin nhắn trong một cuộc trò chuyện
đang hoạt động là không giới hạn.
- Bạn có thể gửi emoji như một phần của văn bản
message. - Các
mediaUrlscủa Facebook và Instagram phải kết thúc bằng một phần mở rộng đã biết. Việc bao gồm các tham số truy vấn sẽ khiến url media thất bại.
Tham số Header
Tham số Path
Nền tảng để gửi tin nhắn:
facebook, instagram, twitterTham số Body
ID của người nhận tin nhắn.
Tin nhắn để gửi cho người nhận.
- Tin nhắn Facebook và Instagram có thể là chuỗi rỗng hoặc không được bao gồm nếu
mediaUrlsđược cung cấp. - X yêu cầu một tin nhắn có ít nhất một ký tự ngay cả khi
mediaUrlsđược cung cấp.
Mảng các URL media để đính kèm hình ảnh, video hoặc tin nhắn thoại.
- Các URL của các mục media phải kết thúc bằng phần mở rộng tệp mà không có tham số bổ sung nào được thêm vào.
- Facebook và Instagram hỗ trợ nhiều URL media.
- X chỉ chấp nhận một URL media duy nhất.
- Tin nhắn thoại được hỗ trợ trên Facebook và Instagram dưới dạng tệp
aachoặcwav.
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"message": "What's up!", "recipientId": "283j839222"} \
-X POST https://api.ayrshare.com/api/messages/instagram
const apiKey = 'API_KEY';
const url = 'https://api.ayrshare.com/api/messages/instagram';
const data = {
message: "What's up!",
recipientId: '283j839222',
};
const headers = {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
};
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
console.log('Response:', data);
})
.catch(error => {
console.error('Error:', error);
});
import requests
api_key = 'API_KEY'
url = 'https://api.ayrshare.com/api/messages/instagram'
data = {
'message': "What's up!",
'recipientId': '283j839222',
}
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json',
}
response = requests.post(url, json=data, headers=headers)
print('Response:', response.json())
<?php
$apiKey = 'API_KEY';
$url = 'https://api.ayrshare.com/api/messages/instagram';
$data = [
'message' => "What's up!",
'recipientId' => '283j839222',
];
$headers = [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
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 {
$responseData = json_decode($response, true);
print_r($responseData);
}
curl_close($ch);
?>
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiKey = "API_KEY";
string url = "https://api.ayrshare.com/api/messages/instagram";
var data = new
{
message = "What's up!",
recipientId = "283j839222"
};
var jsonData = JsonSerializer.Serialize(data);
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
try
{
var response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var responseData = JsonSerializer.Deserialize<dynamic>(responseBody);
Console.WriteLine("Response:");
Console.WriteLine(responseData);
}
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/instagram";
String data = "{\"message\": \"What's up!\", \"recipientId\": \"283j839222\"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(data))
.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());
}
}
}
{ // tin nhắn văn bản đơn
"status": "success",
"recipientId": "72706337063589124",
"messageId": "aWdfZAG1faXRlbToxOkl",
"message": "What is up?"
}
{
// tin nhắn văn bản đơn
"action": "messages",
"status": "error",
"code": 363,
"message": "The recipient ID was not found. Please confirm the recipient ID is correct."
}
{
// hình ảnh đơn
"status": "success",
"recipientId": "761943",
"messageId": "m_EgvfBrgjaM",
"type": "image",
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg"
}
{
// tin nhắn văn bản và hình ảnh
"action": "send",
"status": "error",
"code": 337,
"message": "Error sending message.",
"messages": [
{
"recipientId": "727063370635",
"messageId": "aWdfZAG1faXRlbT",
"message": "What a great day"
},
{
"action": "messages",
"status": "error",
"code": 365,
"message": "An error occurred sending the message attachment. Please verify the attachment is still available and try again."
}
]
}
⌘I
