NAVNavbar
Logo
cURL php NodeJS Python cSharp

Content Analysis – Sentiment Analysis API


This endpoint will provide you with sentiment analysis data for the citations available for the target keyword.

Instead of ‘login’ and ‘password’ use your credentials from https://app.dataforseo.com/api-access

<?php
// You can download this file from here https://cdn.dataforseo.com/v3/examples/php/php_RestClient.zip
require('RestClient.php');
$api_url = 'https://api.dataforseo.com/';
// Instead of 'login' and 'password' use your credentials from https://app.dataforseo.com/api-access
$client = new RestClient($api_url, null, 'login', 'password');
$post_array = array();
// simple way to set a task
$post_array[] = array(
   "keyword" => "logitech",
   "search_mode" => "as_is",
   "internal_list_limit" => 1
);
try {
   // POST /v3/content_analysis/sentiment_analysis/live
   $result = $client->post('/v3/content_analysis/sentiment_analysis/live', $post_array);
   print_r($result);
   // do something with post result
} catch (RestClientException $e) {
   echo "n";
   print "HTTP code: {$e->getHttpCode()}n";
   print "Error code: {$e->getCode()}n";
   print "Message: {$e->getMessage()}n";
   print  $e->getTraceAsString();
   echo "n";
}
$client = null;
?>

The above command returns JSON structured like this:

{
  "version": "0.1.20220819",
  "status_code": 20000,
  "status_message": "Ok.",
  "time": "23.0121 sec.",
  "cost": 0.02003,
  "tasks_count": 1,
  "tasks_error": 0,
  "tasks": [
    {
      "id": "11091707-1535-0465-0000-07fd1ba1463b",
      "status_code": 20000,
      "status_message": "Ok.",
      "time": "22.9506 sec.",
      "cost": 0.02003,
      "result_count": 1,
      "path": [
        "v3",
        "content_analysis",
        "sentiment_analysis",
        "live"
      ],
      "data": {
        "api": "content_analysis",
        "function": "sentiment_analysis",
        "keyword": "logitech",
        "search_mode": "as_is",
        "internal_list_limit": 1
      },
      "result": [
        {
          "type": "content_analysis_sentiment_analysis",
          "positive_connotation_distribution": {
            "positive": {
              "type": "content_analysis_summary",
              "total_count": 2986476,
              "rank": 616,
              "top_domains": [
                {
                  "domain": "vdsitsolutions.com",
                  "count": 384346
                }
              ],
              "sentiment_connotations": {
                "anger": 67,
                "happiness": 151184,
                "love": 8793,
                "sadness": 208,
                "share": 118464,
                "fun": 4955
              },
              "connotation_types": {
                "positive": 2286584,
                "negative": 198296,
                "neutral": 785304
              },
              "text_categories": [
                {
                  "category": null,
                  "count": 308940
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 477645
                }
              ],
              "page_types": {
                "blogs": 1348461,
                "organization": null,
                "news": null,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "BE": 390724
              },
              "languages": {
                "en": 1729629
              }
            },
            "negative": {
              "type": "content_analysis_summary",
              "total_count": 1683708,
              "rank": 638,
              "top_domains": [
                {
                  "domain": "nerdpart.com",
                  "count": 89932
                }
              ],
              "sentiment_connotations": {
                "anger": 147,
                "happiness": 87373,
                "love": 2947,
                "sadness": 708,
                "share": 90589,
                "fun": 4890
              },
              "connotation_types": {
                "positive": 246750,
                "negative": 1176349,
                "neutral": 252617
              },
              "text_categories": [
                {
                  "category": null,
                  "count": 218097
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 342061
                }
              ],
              "page_types": {
                "blogs": 539005,
                "organization": null,
                "news": null,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "US": 100736
              },
              "languages": {
                "en": 689101
              }
            },
            "neutral": {
              "type": "content_analysis_summary",
              "total_count": 2854419,
              "rank": 638,
              "top_domains": [
                {
                  "domain": "xsplit.com",
                  "count": 53696
                }
              ],
              "sentiment_connotations": {
                "anger": 48,
                "happiness": 72433,
                "love": 2073,
                "sadness": 757,
                "share": 90082,
                "fun": 2248
              },
              "connotation_types": {
                "positive": 579995,
                "negative": 182173,
                "neutral": 2437398
              },
              "text_categories": [
                {
                  "category": null,
                  "count": 215128
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 656241
                }
              ],
              "page_types": {
                "blogs": 1468065,
                "organization": null,
                "news": null,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "US": 338896
              },
              "languages": {
                "en": 2441543
              }
            }
          },
          "sentiment_connotation_distribution": {
            "anger": {
              "type": "content_analysis_summary",
              "total_count": 650,
              "rank": 127,
              "top_domains": [
                {
                  "domain": "marktguru.at",
                  "count": 6
                }
              ],
              "sentiment_connotations": {
                "anger": 177,
                "happiness": 114,
                "love": 0,
                "sadness": 2,
                "share": 2,
                "fun": 1
              },
              "connotation_types": {
                "positive": 113,
                "negative": 352,
                "neutral": 139
              },
              "text_categories": [
                {
                  "category": [
                    10013,
                    10108,
                    13691
                  ],
                  "count": 26
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 28
                }
              ],
              "page_types": {
                "blogs": 125,
                "organization": null,
                "news": null,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "DE": 41
              },
              "languages": {
                "de": 498
              }
            },
            "happiness": {
              "type": "content_analysis_summary",
              "total_count": 393934,
              "rank": 549,
              "top_domains": [
                {
                  "domain": "dutchcreativeindustry.com",
                  "count": 11848
                }
              ],
              "sentiment_connotations": {
                "anger": 14,
                "happiness": 223776,
                "love": 888,
                "sadness": 17,
                "share": 3448,
                "fun": 1633
              },
              "connotation_types": {
                "positive": 186779,
                "negative": 94796,
                "neutral": 100161
              },
              "text_categories": [
                {
                  "category": null,
                  "count": 32920
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 59456
                }
              ],
              "page_types": {
                "blogs": 105889,
                "organization": null,
                "news": null,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "DE": 24845
              },
              "languages": {
                "en": 126472
              }
            },
            "love": {
              "type": "content_analysis_summary",
              "total_count": 21252,
              "rank": 418,
              "top_domains": [
                {
                  "domain": "logitech.com",
                  "count": 411
                }
              ],
              "sentiment_connotations": {
                "anger": 0,
                "happiness": 1767,
                "love": 13820,
                "sadness": 3,
                "share": 195,
                "fun": 36
              },
              "connotation_types": {
                "positive": 11551,
                "negative": 4333,
                "neutral": 2950
              },
              "text_categories": [
                {
                  "category": null,
                  "count": 3391
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 2437
                }
              ],
              "page_types": {
                "blogs": null,
                "organization": null,
                "news": 7426,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "US": 1547
              },
              "languages": {
                "ja": 7933
              }
            },
            "sadness": {
              "type": "content_analysis_summary",
              "total_count": 2306,
              "rank": 320,
              "top_domains": [
                {
                  "domain": "balans37.com",
                  "count": 33
                }
              ],
              "sentiment_connotations": {
                "anger": 2,
                "happiness": 31,
                "love": 3,
                "sadness": 1029,
                "share": 19,
                "fun": 4
              },
              "connotation_types": {
                "positive": 298,
                "negative": 1034,
                "neutral": 1116
              },
              "text_categories": [
                {
                  "category": null,
                  "count": 475
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 205
                }
              ],
              "page_types": {
                "blogs": 464,
                "organization": null,
                "news": null,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "US": 88
              },
              "languages": {
                "en": 1264
              }
            },
            "share": {
              "type": "content_analysis_summary",
              "total_count": 459440,
              "rank": 477,
              "top_domains": [
                {
                  "domain": "dutchcreativeindustry.com",
                  "count": 57766
                }
              ],
              "sentiment_connotations": {
                "anger": 2,
                "happiness": 4025,
                "love": 132,
                "sadness": 20,
                "share": 206541,
                "fun": 67
              },
              "connotation_types": {
                "positive": 142178,
                "negative": 105832,
                "neutral": 182464
              },
              "text_categories": [
                {
                  "category": [
                    10001,
                    10024,
                    10185,
                    10952,
                    13573
                  ],
                  "count": 57766
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 46062
                }
              ],
              "page_types": {
                "blogs": null,
                "organization": null,
                "news": 80078,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "WW": 82205
              },
              "languages": {
                "en": 298788
              }
            },
            "fun": {
              "type": "content_analysis_summary",
              "total_count": 19412,
              "rank": 358,
              "top_domains": [
                {
                  "domain": "insidecee.pl",
                  "count": 893
                }
              ],
              "sentiment_connotations": {
                "anger": 1,
                "happiness": 3343,
                "love": 34,
                "sadness": 4,
                "share": 93,
                "fun": 9139
              },
              "connotation_types": {
                "positive": 8604,
                "negative": 6625,
                "neutral": 3980
              },
              "text_categories": [
                {
                  "category": null,
                  "count": 4597
                }
              ],
              "page_categories": [
                {
                  "category": null,
                  "count": 3182
                }
              ],
              "page_types": {
                "blogs": 4867,
                "organization": null,
                "news": null,
                "message-boards": null,
                "ecommerce": null
              },
              "countries": {
                "PL": 1405
              },
              "languages": {
                "fr": 6386
              }
            }
          }
        }
      ]
    }
  ]
}

All POST data should be sent in the JSON format (UTF-8 encoding). The task setting is done using the POST method. When setting a task, you should send all task parameters in the task array of the generic POST array. You can send up to 2000 API calls per minute. The maximum number of requests that can be sent simultaneously is limited to 30.

You can specify the number of results you want to retrieve, filter and sort them.

Below you will find a detailed description of the fields you can use for setting a task.

Description of the fields for setting a task:

Field name Type Description
keyword string target keyword
required field
UTF-8 encoding
the keywords will be converted to a lowercase format;
Note: to match an exact phrase instead of a stand-alone keyword, use double quotes and backslashes;
example:
"keyword": "\"tesla palo alto\""

learn more about rules and limitations of keyword and keywords fields in DataForSEO APIs in this Help Center article

keyword_fields object target keyword fields and target keywords
optional field
use this parameter to filter the dataset by keywords that certain fields should contain;
fields you can specify: title, main_title, previous_title, snippet
you can indicate several fields;
Note: to match an exact phrase instead of a stand-alone keyword, use double quotes and backslashes;
example:
"keyword_fields": {
  "snippet": "\"logitech mouse\"",
  "main_title": "sale"
}
page_type array target page types
optional field
use this parameter to filter the dataset by page types
possible values:
"ecommerce", "news", "blogs", "message-boards", "organization"
internal_list_limit integer maximum number of elements within internal arrays
optional field
you can use this field to limit the number of elements within the following arrays:
top_domains
text_categories
page_categories
countries
languages
default value: 1
maximum value: 20
positive_connotation_threshold float positive connotation threshold
optional field
specified as the probability index threshold for positive sentiment related to the citation content
if you specify this field, connotation_types object in the response will only contain data on citations with positive sentiment probability more than or equal to the specified value
possible values: from 0 to 1
default value: 0.4
sentiments_connotation_threshold float sentiment connotation threshold
optional field
specified as the probability index threshold for sentiment connotations related to the citation content
if you specify this field, sentiment_connotations object in the response will only contain data on citations where the probability per each sentiment is more than or equal to the specified value
possible values: from 0 to 1
default value: 0.4
initial_dataset_filters array initial dataset filtering parameters
optional field
you can add several filters at once (8 filters maximum)
you should set a logical operator and, or between the conditions
the following operators are supported:
regex, not_regex, <, <=, >, >=, =, <>, in, not_in, like,not_like, has, has_not
you can use the % operator with like and not_like to match any string of zero or more characters
example:
["domain","<>", "logitech.com"]

[["domain","<>","logitech.com"],"and",["content_info.connotation_types.negative",">",1000]]

[["domain","<>","logitech.com"]],
"and",
[["content_info.connotation_types.negative",">",1000],
"or",
["content_info.text_category","has",10994]]]

for more information about filters, please refer to Content Analysis API – Filters

tag string user-defined task identifier
optional field
the character limit is 255
you can use this parameter to identify the task and match it with the result
you will find the specified tag value in the data object of the response

As a response of the API server, you will receive JSON-encoded data containing a tasks array with the information specific to the set tasks.

Description of the fields in the results array:

Field name Type Description
version string the current version of the API
status_code integer general status code
you can find the full list of the response codes here
Note: we strongly recommend designing a necessary system for handling related exceptional or error conditions
status_message string general informational message
you can find the full list of general informational messages here
time string execution time, seconds
cost float total tasks cost, USD
tasks_count integer the number of tasks in the tasks array
tasks_error integer the number of tasks in the tasks array returned with an error
tasks array array of tasks
        id string task identifier
unique task identifier in our system in the UUID format
        status_code integer status code of the task
generated by DataForSEO; can be within the following range: 10000-60000
you can find the full list of the response codes here
        status_message string informational message of the task
you can find the full list of general informational messages here
        time string execution time, seconds
        cost float cost of the task, USD
        result_count integer number of elements in the result array
        path array URL path
        data object contains the same parameters that you specified in the POST request
        result array array of results
            type string type of element = ‘content_analysis_sentiment_analysis’
            positive_connotation_distribution object citation distribution by sentiment connotation types
contains objects with citation counts and relevant data distributed by types of sentiments (sentiment polarity);
possible sentiment connotation types: positive, negative, neutral
                $positive object positive, negative, or neutral connotations
variable can take the following values: positive, negative, neutral
                    type string type of element = ‘content_analysis_summary’
                    total_count integer total number of relevant results
                    rank integer rank of all relevant URLs
                    top_domains array top relevant domains
contains objects with top relevant domains and the number of citations per each domain
                    sentiment_connotations object sentiment connotations
contains relevant sentiments (emotional reactions) and the number of citations per each sentiment;
possible connotations: "anger", "happiness", "love", "sadness", "share", "fun"
                    connotation_types object connotation types
contains types of sentiments (sentiment polarity) related to the keyword citation and citation count per each sentiment type;
possible connotation types: "positive", "negative", "neutral"
                    text_categories array text categories
contains text categories and citation count in each text category
to obtain a full list of available categories, refer to the Categories endpoint
                    page_categories array page categories
contains objects with page categories and citation count in each page category
to obtain a full list of available categories, refer to the Categories endpoint
                    page_types object page types
contains page types and citation count per each page type
                    countries object countries
contains countries and citation count in each country
to obtain a full list of available countries, refer to the Locations endpoint
                    languages object languages
to obtain a full list of available languages, refer to the Languages endpoint
            sentiment_connotation_distribution object citation distribution by sentiment connotations
contains objects with citation counts and relevant data distributed by sentiments (emotional reactions);
possible sentiment connotation types: anger, happiness, love, sadness, share, fun
                $anger object sentiment name
variable can take the following values: anger, happiness, love, sadness, share, fun
                    type string type of element = ‘content_analysis_summary’
                    total_count integer total number of relevant results
                    rank integer rank of all relevant URLs
                    top_domains array top relevant domains
contains objects with top relevant domains and the number of citations per each domain
                    sentiment_connotations object sentiment connotations
contains relevant sentiments (emotional reactions) and the number of citations per each sentiment;
possible connotations: "anger", "happiness", "love", "sadness", "share", "fun"
                    connotation_types object connotation types
contains types of sentiments (sentiment polarity) related to the keyword citation and citation count per each sentiment type;
possible connotation types: "positive", "negative", "neutral"
                    text_categories array text categories
contains text categories and citation count in each text category
to obtain a full list of available categories, refer to the Categories endpoint
                    page_categories array page categories
contains objects with page categories and citation count in each page category
to obtain a full list of available categories, refer to the Categories endpoint
                    page_types object page types
contains page types and citation count per each page type
                    countries object countries
contains countries and citation count in each country
to obtain a full list of available countries, refer to the Locations endpoint
                    languages object languages
to obtain a full list of available countries, refer to the Languages endpoint

‌‌