# Perform sentiment analysis by using the gcloud tool

This page shows you how to get started with the Cloud Natural Language API using the
Google Cloud SDK.

*** ** * ** ***

To follow step-by-step guidance for this task directly in the
Google Cloud console, click **Guide me**:

[Guide me](https://console.cloud.google.com/freetrial?redirectPath=/home/dashboard?tutorial%3Dnatural-language__quickstart)

*** ** * ** ***

## Before you begin

<br />

## Make an entity analysis request

### gcloud

Use the `gcloud` command line tool to call the `analyze-entities` command and use the `--content` flag to specify the text to analyze.

    gcloud ml language analyze-entities --content="Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'."

### Command-line

Use `curl` to make a `POST` request to the `documents:analyzeEntities` method and provide the appropriate request body as shown in the following example.

<br />

The example uses the `gcloud auth application-default print-access-token`
command to obtain an access token for the service account that you created
when you set up the project.

```bash
curl -X POST \
  -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
  -H "Content-Type: application/json; charset=utf-8" \
 "https://language.googleapis.com/v1/documents:analyzeEntities" \
  --data "{
  'document':{
    'type':'PLAIN_TEXT',
    'content':'Michelangelo Caravaggio, Italian painter, is known for
              \'The Calling of Saint Matthew\'.'
  },
  'encodingType':'UTF8'
}"
```

You should see a response similar to the following:

```json
{
  "entities": [
    {
      "name": "Michelangelo Caravaggio",
      "type": "PERSON",
      "metadata": {
        "wikipedia_url": "http://en.wikipedia.org/wiki/Caravaggio",
        "mid": "/m/020bg"
      },
      "salience": 0.83047235,
      "mentions": [
        {
          "text": {
            "content": "Michelangelo Caravaggio",
            "beginOffset": 0
          },
          "type": "PROPER"
        },
        {
          "text": {
            "content": "painter",
            "beginOffset": 33
          },
          "type": "COMMON"
        }
      ]
    },
    {
      "name": "Italian",
      "type": "LOCATION",
      "metadata": {
        "mid": "/m/03rjj",
        "wikipedia_url": "http://en.wikipedia.org/wiki/Italy"
      },
      "salience": 0.13870546,
      "mentions": [
        {
          "text": {
            "content": "Italian",
            "beginOffset": 25
          },
          "type": "PROPER"
        }
      ]
    },
    {
      "name": "The Calling of Saint Matthew",
      "type": "EVENT",
      "metadata": {
        "mid": "/m/085_p7",
        "wikipedia_url": "http://en.wikipedia.org/wiki/The_Calling_of_St_Matthew_(Caravaggio)"
      },
      "salience": 0.030822212,
      "mentions": [
        {
          "text": {
            "content": "The Calling of Saint Matthew",
            "beginOffset": 69
          },
          "type": "PROPER"
        }
      ]
    }
  ],
  "language": "en"
}
```

> [!NOTE]
> You can also analyze document sentiment and extract syntax annotations from text by making requests to different Cloud Natural Language API endpoints. See the [Cloud Natural Language API
> Basics](https://docs.cloud.google.com/natural-language/docs/basics) for more details.

## Clean up

> [!CAUTION]
> **Caution** : Deleting a project has the following effects:
>
> - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
> - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.
>
>
> If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects
> can help you avoid exceeding project quota limits.

1. In the Google Cloud console, go to the **Manage resources** page.

   [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)
2. In the project list, select the project that you want to delete, and then click **Delete**.
3. In the dialog, type the project ID, and then click **Shut down** to delete the project.

<br />

## What's next

- Get started with the Natural Language API in your language of choice by using
  a [Cloud Natural Language Client Library](https://docs.cloud.google.com/natural-language/docs/reference/libraries).

- Consult the [Natural Language Basics](https://docs.cloud.google.com/natural-language/docs/basics) for
  conceptual information on forming Natural Language API requests and handling
  responses.

- Try the
  [Sentiment Analysis Tutorial](https://docs.cloud.google.com/natural-language/docs/sentiment-tutorial) and
  browse the [Sample Applications](https://docs.cloud.google.com/natural-language/docs/sample-apps).