Documentation for getMetrics Logic
Overview
This node retrieve metrics from specified tweets using their unique identifiers (tweet IDs). It connects to a third-party integration to gather relevant data, processes the inputs, and formats the output, making it an essential tool for users and applications that analyze Twitter data.
Settings
1. tweetIds
- Input Type: String (comma-separated) or Array
- Description: This setting accepts either a comma-separated string of tweet IDs or an array of tweet IDs. It is essential for determining which tweets to retrieve metrics for. If no tweet IDs are provided, the logic will return an error.
- Default Value: An empty string (
''). If not specified in the inputs or configuration, it defaults to an empty state leading to an error return.
2. fields
- Input Type: String (comma-separated) or Array
- Description: This setting indicates the specific fields of metrics to retrieve from the tweets. The default fields include
id,text,created_at,public_metrics,non_public_metrics, andorganic_metrics. Changing this setting allows the user to restrict or expand the metrics returned based on their needs. - Default Value:
'id,text,created_at,public_metrics,non_public_metrics,organic_metrics'. If not specified, it defaults to these standard fields.
3. context
- Input Type: Object
- Description: This setting includes context information necessary for building the connection to the third-party integration. The context is essential for authentication and may include user credentials or configuration settings required by the integration.
- Default Value: Not explicitly defined; expected to be provided when calling the node.
How It Works
-
Input Handling: The logic first extracts the
tweetIdsandfieldseither from the providedinputsor from theconfig. IftweetIdsis empty, it returns an error immediately, ensuring that a valid input is always necessary for processing. -
Tweet ID Normalization: The logic normalizes the input to ensure that it always operates on an array of tweet IDs. It trims whitespace and filters out any empty strings.
-
Integration Setup: It uses the a secure connection with the third-party integration based on the given
context. -
Data Retrieval: It calls the
getTweetMetricsmethod from the integration to fetch metrics for the specified tweet IDs and requested fields. -
Error Handling: If any error occurs during the integration call, it captures the error and returns a relevant message.
-
Output: The function returns the retrieved tweet metrics in the form of an output object, which can then be utilized by the calling process.
Data Expectations
tweetIds: Must contain valid tweet IDs, either as a comma-separated string or an array format. Valid tweet IDs are necessary for successful API calls and must not be empty.fields: Must be a comma-separated string or an array specifying the metrics to retrieve. If an invalid field is specified, the third-party integration will determine how to handle it based on its own API documentation.
Use Cases & Examples
Use Case 1: Social Media Analysis for Marketing Campaigns
A marketing team wants to analyze the engagement metrics of specific tweets related to their latest product launch to understand how well their audience is responding.
Use Case 2: Public Sentiment Tracking
A data analyst is tasked with monitoring public sentiment towards current events by retrieving metrics from tweets that mention a particular topic or hashtag.
Use Case 3: Historical Data Capture
Researchers studying the influence of social media on public opinion want to retrieve historical metrics on tweets related to significant events.
Example Configuration
For the Social Media Analysis for Marketing Campaigns use case, suppose the team wants to examine the metrics for the following tweet IDs: 12345, 67890. They want to gather the public_metrics and text fields only.
Sample Configuration
{
"inputs": {
"tweetIds": "12345, 67890",
"fields": "public_metrics,text"
},
"config": {},
"context": {
"apiKey": "your_api_key",
"userId": "your_user_id"
}
}Expected Output
If the tweet IDs are valid and the API call is successful, the output may look something like this:
{
"output1": [
{
"id": "12345",
"text": "Excited about the new product launch!",
"public_metrics": {
"retweet_count": 50,
"reply_count": 20,
"like_count": 100,
"quote_count": 10
}
},
{
"id": "67890",
"text": "Feeling great about our new features!",
"public_metrics": {
"retweet_count": 30,
"reply_count": 15,
"like_count": 75,
"quote_count": 5
}
}
]
}This example illustrates how the logic can be configured and executed to extract valuable insights from tweets relevant to marketing strategies.