curl --location "https://api.ayrshare.com/api/validate/post" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer API_KEY" \
--data '{
"post": "This is amazing",
"platforms": [
"facebook"
],
"mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"]
}'
const apiKey = 'API_KEY'; // Replace with your actual API key
const requestData = {
post: "This is amazing",
platforms: ["facebook"],
mediaUrls: ["https://img.ayrshare.com/012/gb.jpg"]
};
fetch('https://api.ayrshare.com/api/validate/post', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(requestData)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
import requests
payload = {
'post': 'This is amazing',
'platforms': ['facebook'],
'mediaUrls': ['https://img.ayrshare.com/012/gb.jpg']
}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'
}
r = requests.post(
'https://api.ayrshare.com/api/validate/post',
json=payload,
headers=headers
)
print(r.json())
<?php
$payload = [
'post' => 'This is amazing',
'platforms' => ['facebook'],
'mediaUrls' => ['https://img.ayrshare.com/012/gb.jpg']
];
$headers = [
'Content-Type: application/json',
'Authorization: Bearer API_KEY'
];
$ch = curl_init('https://api.ayrshare.com/api/validate/post');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
print_r($result);
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var payload = new
{
post = "This is amazing",
platforms = new[] { "facebook" },
mediaUrls = new[] { "https://img.ayrshare.com/012/gb.jpg" }
};
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
try
{
var response = await client.PostAsJsonAsync(
"https://api.ayrshare.com/api/validate/post",
payload
);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
)
type PostRequest struct {
Post string `json:"post"`
Platforms []string `json:"platforms"`
MediaUrls []string `json:"mediaUrls"`
}
func main() {
// Create the request payload
payload := PostRequest{
Post: "This is amazing",
Platforms: []string{"facebook"},
MediaUrls: []string{"https://img.ayrshare.com/012/gb.jpg"},
}
// Convert payload to JSON
jsonData, err := json.Marshal(payload)
if err != nil {
log.Fatalf("Error marshaling JSON: %v", err)
}
// Create the request
req, err := http.NewRequest(
"POST",
"https://api.ayrshare.com/api/validate/post",
bytes.NewBuffer(jsonData),
)
if err != nil {
log.Fatalf("Error creating request: %v", err)
}
// Set headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer API_KEY")
// Make the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatalf("Error making request: %v", err)
}
defer resp.Body.Close()
// Read the response
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Error reading response: %v", err)
}
// Print the response
fmt.Println(string(body))
}
{
"status": "success",
"message": "No validation issues were found with this post. This is only an Ayrshare validation test and the post may still return an error by the social networks.",
}
{
"status": "success",
"message": "No validation issues were found with this post. This is only an Ayrshare validation test and the post may still return an error by the social networks.",
"warnings": [
{
"action": "post",
"status": "error",
"code": 156,
"message": "Twitter is not linked with Ayrshare. Please confirm the linkage on the Social Accounts page in your dashboard."
}
]
}
{
"action": "post",
"status": "error",
"code": 136,
"message": "Media URLs invalid. Please verify the media is an externally accessible URL."
}
Validate
校验帖子
在发布前校验帖子
POST
/
validate
/
post
curl --location "https://api.ayrshare.com/api/validate/post" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer API_KEY" \
--data '{
"post": "This is amazing",
"platforms": [
"facebook"
],
"mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"]
}'
const apiKey = 'API_KEY'; // Replace with your actual API key
const requestData = {
post: "This is amazing",
platforms: ["facebook"],
mediaUrls: ["https://img.ayrshare.com/012/gb.jpg"]
};
fetch('https://api.ayrshare.com/api/validate/post', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(requestData)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
import requests
payload = {
'post': 'This is amazing',
'platforms': ['facebook'],
'mediaUrls': ['https://img.ayrshare.com/012/gb.jpg']
}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'
}
r = requests.post(
'https://api.ayrshare.com/api/validate/post',
json=payload,
headers=headers
)
print(r.json())
<?php
$payload = [
'post' => 'This is amazing',
'platforms' => ['facebook'],
'mediaUrls' => ['https://img.ayrshare.com/012/gb.jpg']
];
$headers = [
'Content-Type: application/json',
'Authorization: Bearer API_KEY'
];
$ch = curl_init('https://api.ayrshare.com/api/validate/post');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
print_r($result);
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var payload = new
{
post = "This is amazing",
platforms = new[] { "facebook" },
mediaUrls = new[] { "https://img.ayrshare.com/012/gb.jpg" }
};
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
try
{
var response = await client.PostAsJsonAsync(
"https://api.ayrshare.com/api/validate/post",
payload
);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
)
type PostRequest struct {
Post string `json:"post"`
Platforms []string `json:"platforms"`
MediaUrls []string `json:"mediaUrls"`
}
func main() {
// Create the request payload
payload := PostRequest{
Post: "This is amazing",
Platforms: []string{"facebook"},
MediaUrls: []string{"https://img.ayrshare.com/012/gb.jpg"},
}
// Convert payload to JSON
jsonData, err := json.Marshal(payload)
if err != nil {
log.Fatalf("Error marshaling JSON: %v", err)
}
// Create the request
req, err := http.NewRequest(
"POST",
"https://api.ayrshare.com/api/validate/post",
bytes.NewBuffer(jsonData),
)
if err != nil {
log.Fatalf("Error creating request: %v", err)
}
// Set headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer API_KEY")
// Make the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatalf("Error making request: %v", err)
}
defer resp.Body.Close()
// Read the response
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Error reading response: %v", err)
}
// Print the response
fmt.Println(string(body))
}
{
"status": "success",
"message": "No validation issues were found with this post. This is only an Ayrshare validation test and the post may still return an error by the social networks.",
}
{
"status": "success",
"message": "No validation issues were found with this post. This is only an Ayrshare validation test and the post may still return an error by the social networks.",
"warnings": [
{
"action": "post",
"status": "error",
"code": 156,
"message": "Twitter is not linked with Ayrshare. Please confirm the linkage on the Social Accounts page in your dashboard."
}
]
}
{
"action": "post",
"status": "error",
"code": 136,
"message": "Media URLs invalid. Please verify the media is an externally accessible URL."
}
在发布帖子之前,你可以先验证内容和参数是否正确。
将你通常发送给
/post 端点的 JSON 完全相同地发送到 /validate/post 端点,它会在响应中返回发现的任何问题。
- 校验基于 Ayrshare 自有的内部算法。
- 帖子不会被发送到社交网络。
- 即使通过了校验,发布时社交网络仍可能返回错误。
Header 参数
Body 参数
发送的 body 与你发送给 /post 端点时使用的相同。curl --location "https://api.ayrshare.com/api/validate/post" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer API_KEY" \
--data '{
"post": "This is amazing",
"platforms": [
"facebook"
],
"mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"]
}'
const apiKey = 'API_KEY'; // Replace with your actual API key
const requestData = {
post: "This is amazing",
platforms: ["facebook"],
mediaUrls: ["https://img.ayrshare.com/012/gb.jpg"]
};
fetch('https://api.ayrshare.com/api/validate/post', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(requestData)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
import requests
payload = {
'post': 'This is amazing',
'platforms': ['facebook'],
'mediaUrls': ['https://img.ayrshare.com/012/gb.jpg']
}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'
}
r = requests.post(
'https://api.ayrshare.com/api/validate/post',
json=payload,
headers=headers
)
print(r.json())
<?php
$payload = [
'post' => 'This is amazing',
'platforms' => ['facebook'],
'mediaUrls' => ['https://img.ayrshare.com/012/gb.jpg']
];
$headers = [
'Content-Type: application/json',
'Authorization: Bearer API_KEY'
];
$ch = curl_init('https://api.ayrshare.com/api/validate/post');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
print_r($result);
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var payload = new
{
post = "This is amazing",
platforms = new[] { "facebook" },
mediaUrls = new[] { "https://img.ayrshare.com/012/gb.jpg" }
};
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
try
{
var response = await client.PostAsJsonAsync(
"https://api.ayrshare.com/api/validate/post",
payload
);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
)
type PostRequest struct {
Post string `json:"post"`
Platforms []string `json:"platforms"`
MediaUrls []string `json:"mediaUrls"`
}
func main() {
// Create the request payload
payload := PostRequest{
Post: "This is amazing",
Platforms: []string{"facebook"},
MediaUrls: []string{"https://img.ayrshare.com/012/gb.jpg"},
}
// Convert payload to JSON
jsonData, err := json.Marshal(payload)
if err != nil {
log.Fatalf("Error marshaling JSON: %v", err)
}
// Create the request
req, err := http.NewRequest(
"POST",
"https://api.ayrshare.com/api/validate/post",
bytes.NewBuffer(jsonData),
)
if err != nil {
log.Fatalf("Error creating request: %v", err)
}
// Set headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer API_KEY")
// Make the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatalf("Error making request: %v", err)
}
defer resp.Body.Close()
// Read the response
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Error reading response: %v", err)
}
// Print the response
fmt.Println(string(body))
}
{
"status": "success",
"message": "No validation issues were found with this post. This is only an Ayrshare validation test and the post may still return an error by the social networks.",
}
{
"status": "success",
"message": "No validation issues were found with this post. This is only an Ayrshare validation test and the post may still return an error by the social networks.",
"warnings": [
{
"action": "post",
"status": "error",
"code": 156,
"message": "Twitter is not linked with Ayrshare. Please confirm the linkage on the Social Accounts page in your dashboard."
}
]
}
{
"action": "post",
"status": "error",
"code": 136,
"message": "Media URLs invalid. Please verify the media is an externally accessible URL."
}
⌘I
