Enhance Instagram Engagement with User Interaction Actions

The Instagram User Interaction And Content API offers developers a powerful suite of Cognitive Actions designed to enhance user engagement through music and video content. With the increasing popularity of audio and visual storytelling on social media, these actions enable seamless integration of Instagram's rich media capabilities into applications, leading to faster deployment and improved user experiences.
This API provides developers with the tools to fetch audio details, search through Instagram's vast audio library, and execute targeted searches for engaging video content. Whether you're building a marketing tool, a content creation app, or a social media analytics platform, these actions simplify the process of interacting with Instagram's multimedia resources.
Use Cases
- Music Apps: Integrate trending audio tracks from Instagram to enhance user-generated content.
- Content Creation Tools: Allow users to search and embed videos or audio clips directly from Instagram into their projects.
- Marketing Platforms: Analyze popular content trends on Instagram to inform marketing strategies and campaigns.
Fetch Audio Details and Reels
The Fetch Audio Details and Reels action retrieves detailed information and associated reels for a specific audio or music track using either an audio_canonical_id or audio_id. This action is crucial for applications that want to provide users with insights about the audio used in various reels, including its creator and usage statistics.
Input Requirements
- audioUniqueId: A unique identifier for the audio resource (required).
- audioStandardId: An identifier for the standard audio (optional, with a default value).
- pageToken: A token for paginated results (optional).
- includeContent: A boolean to include content details in the response (optional).
- urlSecureEmbed: A boolean to request a secure HTTPS URL for embedding (optional).
Expected Output
The output includes:
- Title of the audio
- Artist information (ID, username, full name)
- Audio ID
- Total posts and total reels associated with the audio
- Download URL for the audio
This allows developers to present rich audio metadata to users, enhancing their experience with audio content on their platforms.
```python
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "03742bd6-375f-455a-82f4-e8a0de9d66cf" # Action ID for: Fetch Audio Details and Reels
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"audioStandardId": "18404792044021762"
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
### Use Cases for this Action
- **Music Discovery:** Enable users to discover popular tracks and the creators behind them.
- **Content Curation:** Help users curate content for their own reels by providing direct access to trending audio.
- **Analytics:** Offer insights into which audio tracks are being used most frequently across the platform, helping creators identify trends.
## Search Instagram Audios
The **Search Instagram Audios** action allows developers to perform a search query to find audios available on Instagram's platform using a specified term or phrase. This functionality can significantly enhance user engagement by making it easier to find specific audio tracks for their content.
### Input Requirements
- **searchQuery**: The term or phrase to search for (required, defaults to "pop").
### Expected Output
The output will include:
- **Count** of the search results
- A list of **audio items** with details such as:
- Title
- Artist
- Duration
- Cover artwork URI
This provides developers with a robust way to integrate audio search functionalities into their applications.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "8f4c4d9f-022d-4363-8c88-c4361d4ac903" # Action ID for: Search Instagram Audios
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"searchQuery": "pop"
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
### Use Cases for this Action
- **User Engagement:** Allow users to search for and select audio tracks that resonate with their content themes.
- **Content Creation:** Facilitate the creation of engaging reels by allowing users to find suitable audio quickly.
- **Marketing Insights:** Analyze what types of audio are popular based on search queries to inform content strategies.
## Execute Reels Search
The **Execute Reels Search** action performs a search operation on Instagram Reels to retrieve relevant video content based on a specific search query. This action supports pagination and safe URL embedding, making it ideal for developers looking to create engaging applications that leverage Instagram's video content.
### Input Requirements
- **searchQuery**: The string to search for in the database (required, defaults to "mrbeast").
- **paginationToken**: A token to retrieve the next page of results (optional).
- **isUrlEmbeddedSafely**: Indicates whether URLs are embedded safely (optional).
### Expected Output
The output includes:
- **Count** of the search results
- A list of **items** that match the search query, including user details, caption, and video URLs.
This allows developers to create rich user experiences centered around video content on Instagram.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "f6936c1e-d143-4cc2-8b3c-44c8d9d52d8a" # Action ID for: Execute Reels Search
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"searchQuery": "mrbeast"
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
### Use Cases for this Action
- **Video Curation:** Help users find videos related to specific themes or trends.
- **Social Media Analytics:** Provide insights into popular content by analyzing search results and engagement metrics.
- **Content Promotion:** Allow businesses to promote their content by embedding relevant Instagram Reels directly into their platforms.
### Conclusion
Integrating the **Instagram User Interaction And Content API** into your applications can significantly enhance user engagement through rich audio and video content. By leveraging actions like fetching audio details, searching for audios, and executing reels searches, developers can provide users with the tools they need to create compelling content. Explore these actions today to elevate your application's capabilities on Instagram.