How to use Ayrshare’s Comments API Endpoint

[ad_1]
Comments can be a huge driver of engagement on social media—whether it’s a compliment, a reply, or the occasional emoji. With Ayrshare’s Comments API Endpoint, you can manage comments automatically across multiple platforms, making it easy to stay on top of responses, especially when dealing with a large number of posts and comments. If you use Facebook, Instagram, LinkedIn, Reddit, TikTok, X/Twitter, or YouTube pages, you will find this article useful.
Let’s dive into how to use Ayrshare’s Comments API Endpoint, including a handy tip for automatically adding the first comment—a technique that can help improve visibility and jump-start engagement on your posts.
What is Ayrshare Comments Endpoint?
Ayrshare Comments Endpoint is a feature that allows you to manage comments on your social media posts. With it, you can:
- Return comments from various forums
- Add a new comment to your post
- Delete and hide comments
- Add the first comment
- Monitor and respond to audience feedback automatically
Using this endpoint is very important for businesses and content creators who want to simplify their social media management, improve response times, and encourage more engagement on posts.
How to use the Ayrshare Comments API
To start using the Ayrshare Comments API, you will first need a paid Ayrshare account and an API key. Let’s go through the first tasks of this ending.
Before adding comments to a post, you first need to have a post to add comments to. With Ayrshare you can collect all posts to find connected social networks and use the returned post ID to publish comments. However, in this tutorial we recommend that you publish new public posts via the /post endpoint. What is returned will be the post ID, which we will use below. See the quick start guide for details.
Step 1: Publish the Post
Publish new comments to existing social media posts on multiple social media platforms, use the POST
/
comment
endpoint.
Example in cURL:
curl
-H "Authorization: Bearer API_KEY"
-H 'Content-Type: application/json'
-d '{"id": "Ut1fWU6XkqkMayHGnJZ", "platforms": ["facebook", "instagram", "linkedin", "reddit", "tiktok", "twitter", "youtube"], "comment": "An amazing comment!"}'
-X POST
Replace it YOUR_API_KEY
with your original API key and POST_ID
with the ID of the target post, returned from the published post call – see know. I platform
field specifies which social network you are targeting, in this example facebook
, instagram
, linkedin
, reddit
, tiktok
, twitter
again youtube
.
What is returned will be a JSON object for the state of the social network:
{
"facebook": {
"status": "success",
// Facebook Social Comment ID
"commentId": "358482752285927_363474831785719",
"comment": "The best comment ever!",
"platform": "facebook"
},
"instagram": {
"status": "success",
// Instagram Social Comment ID
"commentId": "17060111860440276",
"comment": "The best comment ever!",
"platform": "instagram"
},
"linkedin": {
"status": "success",
// LinkedIn Social Comment ID
"commentId": "urn:li:comment:(urn:li:activity:7141202289402236928,7141205176207503360)",
"comment": "Someone’s sitting in the shade today because someone planted a tree a long time ago. - Warren Buffett",
// Social comment Id from LinkedIn
"commentUrn": "urn:li:comment:(urn:li:activity:7141202289402236928,7141205176207503360)",
"platform": "linkedin"
},
"youtube": {
"status": "success",
// YouTube Social Comment ID
"commentId": "UgzIEZsDQKXgHsEnwTR4AaABAa",
"comment": "The best comment ever!",
"platform": "youtube"
},
"tiktok": {
"status": "success",
// TikTok Social Comment ID
"commentId": "7260964914699764524",
"comment": "The best comment ever!",
"platform": "tiktok",
"videoId": "7260964048362310959"
},
"twitter": {
"status": "success",
// Twitter Social Comment ID
"commentId": "1525632403262101648",
"comment": "The best comment ever!",
"postUrl": "
},
"status": "success",
// Ayrshare Comment ID. Used for replying to a comment.
"commentID": "IUDSCfdYfFkw_dWhW9PLI",
// Ayrshare Post ID
"id": "Ut1fWU6XkqlMayHGnJZ"
}
Step 2: Return the Comment
Retrieving comments is useful when you want to analyze feedback or show evidence of interactions with people on other platforms. Here’s how to get comments on a post:
- Send a GET request to the comment repository with your API key and a specific post ID.
- This request will return all comments related to that post.
Example in JavaScript:
const API_KEY = "API_KEY";
fetch("https://app.ayrshare.com/api/comments/Ut1fWU6XkqkMayHGnJZ", {
method: "GET",
headers: {
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
You will send post ID – Ut1fWU6XkqkMayHGnJZ
– to get all the comments of this post. This application will then return a list of comments with statistics, such as a count, of the specified post from all forums the post has been published. Also included will be responses to comments, so you can view the entire thread.
The response will contain the comment array, including information such as the comment content, author, timestamp, and other relevant metadata including the comment ID.
{
"facebook": [
{
"comment": "What a great comment",
// Facebook Social Comment ID
"commentId": "806720068141593_1849585385469876",
"commentCount": 3,
"created": "2024-02-27T19:55:28Z",
// If available. Facebook determines availability based on the user's security profile and settings.
"from": {
"name": "John Smith",
"id": "5075334022535844"
},
"likeCount": 342,
"platform": "facebook",
// If available. Facebook determines availability based on the user's security profile and settings.
"userName": "WondrousTimes",
"userLikes": false,
// Facebook replies to replies have the same parent id regardless of nesting.
"replies": [
{
"comment": "Nice Comment 2",
"commentId": "806720068141593_320599703877348",
"commentCount": 0,
"company": true,
"created": "2024-02-27T19:55:40Z",
"from": {
"name": "Sue Me",
"id": "5075334022535800"
},
"likeCount": 3,
"parent": {
"createdTime": "2024-02-27T19:55:28+0000",
"from": {
"name": "John Smith",
"id": "5075334022535844"
},
"message": "What a great comment",
"id": "806720068141593_1849585385469876"
},
"platform": "facebook",
"userLikes": false
}
]
}
],
"instagram": [
{
"comment": "Love this post.",
// Instagram Social Comment ID
"commentId": "18030599567251077",
"created": "2022-10-13T00:52:47Z",
// If available. Instagram determines availability based on the user's security profile and settings.
"from": {
"name": "WondrousTimes",
"id": "112775157855689"
},
// Is the comment hidden
"hidden": false,
"likeCount": 1,
// The Instagram Social ID of the parent post. Only returned when using get by ID on a reply.
"parentId": "17999860012861",
"platform": "instagram",
"replies": [
{
"created": "2024-04-04T22:37:39Z",
"from": {
"id": "178414522127073334",
"username": "ayrshare"
},
"hidden": false,
// Instagram Social Comment Id
"id": "18023114651100610",
"likeCount": 2,
"parentId": "178438334431963234",
"text": "@ayrshare Thanks",
"user": {
"id": "17841452212702234"
},
"username": "ayrshare"
}
],
// ID of Instagram user who created the comment.
"user": {
"id": "17841452212707498"
},
// Instagram determines availability based on the user's security profile and settings.
"userName": "ayrshare"
}
],
"status": "success",
"id": "Ut2fWU6XkqkMayHGnJZ7",
"lastUpdated": "2023-03-26T22:30:13.035Z",
"nextUpdate": "2023-03-26T22:41:13.035Z"
}
Step 3: Reply to the comments
Adding comments to existing posts allows you to interact with users directly from the Ayrshare API. This can be especially useful if you have an automated process for answering frequently asked questions or engaging with users who mention your product.
- Send a POST request to the end of the response comment with your comment ID and comment text.
- Ayrshare will automatically add comments to posts on the appropriate social media platform.
- You can also find all comments on posts you don’t publish.
Example in Python:
import requests
payload = {'commentId': 'Ut1fWU6XkqkMayHGnJZ',
'platforms': ['facebook', 'instagram', 'linkedin', 'twitter', 'youtube'],
'comment': 'An amaxing comment!'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://app.ayrshare.com/api/comments/reply',
json=payload,
headers=headers)
print(r.json())
I commentId
field – Ut1fWU6XkqkMayHGnJZ
– contains the ID of the comment you are replying to, which ensures that your reply is linked correctly.
When a feedback comment is submitted, Ayrshare will confirm with a success message and return information about the comment.
Step 4: Delete the Comment
To delete a comment, use the DELETE /comment
endpoint.
Example in PHP:
$apiUrl = 'https://app.ayrshare.com/api/comments/Ut1fWU6XkqkMayHGnJZ'; // Replace with your post ID
$apiKey = 'API_KEY'; // Replace 'API_KEY' with your actual API key
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey,
];
$curl = curl_init($apiUrl);
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => $headers
]);
$response = curl_exec($curl);
if ($response === false) {
echo 'Curl error: ' . curl_error($curl);
} else {
echo json_encode(json_decode($response), JSON_PRETTY_PRINT);
}
curl_close($curl);
Enter Comment ID – Ut1fWU6XkqkMayHGnJZ
– for the comment you want to delete as a method parameter with the ID of the comment you want to delete. Use this feature wisely as part of your content moderation strategy.
Disables comments on social media posts
A nice feature is being able to disable commenting on posts. For example, you may not want to moderate comments on certain posts. To disable comments on a post just add a field disableComments
when creating an original post or updating an existing post.
Example in cURL:
curl
-H "Authorization: Bearer API_KEY"
-H 'Content-Type: request/json'
-d '{"post": "Today is a good day!", "platforms": ["instagram", "linkedin"]"disableComments": true, "mediaUrls": ["
-X POST
Set disable
Comments to true
to disable comments, or false
to enable them. This feature’s is available for Instagram, LinkedIn, and TikTok.
How to Automatically Add a First Comment
Adding a first comment immediately after posting is a clever technique to boost engagement. This first comment often provides additional context, adds a call-to-action, or includes relevant hashtags that don’t clutter the main post.
Ayrshare makes this incredibly simple since you can send the first comment directly at the same time that you create the post.
Example Code Workflow:
POST /api/post
Headers:
- Authorization: Bearer YOUR_API_KEY
Body:
{
post: "Today is a great day!", // required
platforms: ["twitter", "facebook"], // required
firstComment: {
"comment": "My first comment" // required
}
}
Best Practices for Using the Comments API Endpoint
- Be On Time: Timely responses improve relevance and demonstrate attention, making them more impactful.
- Use a CTA (Call to Action): Comments that ask questions or ask for feedback are more likely to get engagement. This can be as simple as “Let us know your thoughts below!” or “Have you tried this?”
- Monitor Spam: When posting comments automatically, be sure to monitor for any spam or irrelevant content. Regularly check the returned comments to ensure a healthy interaction environment.
- Experiment with Hashtags: Use the comment section to add additional hashtags relevant to the post topic. This keeps your main post clean while improving discoverability.
Go ahead
Ayrshare Comments API Endpoints is a powerful tool set to improve your social media communication strategy by allowing you to manage comments on your site, including posting, retrieving, replying, and deleting comments, as well as disabling comments. For advanced commenting options, be sure to check out the full documentation at the bottom of the comments.
[ad_2]
Source link