All Products
Search
Document Center

Object Storage Service:Obtain object tags (PHP SDK V2)

Last Updated:Mar 20, 2026

Use the OSS SDK for PHP V2 to retrieve the tag set associated with an object.

Prerequisites

Before you begin, ensure that you have:

Usage notes

  • The examples in this topic use the China (Hangzhou) region (cn-hangzhou) and the public endpoint. To access OSS from another Alibaba Cloud service in the same region, use the internal endpoint instead. For a list of supported regions and endpoints, see OSS regions and endpoints.

  • Object tagging uses key-value pairs to label an object. For background information, see Object tagging.

  • For the underlying API, see GetObjectTagging.

Get object tags

The following example retrieves all tags on a specified object.

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Load credentials from environment variables.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Initialize the client.
$cfg = Oss\Config::loadDefault();
$cfg->setCredentialsProvider($credentialsProvider);
$cfg->setRegion('cn-hangzhou');

$client = new Oss\Client($cfg);

// Retrieve object tags.
$request = new Oss\Models\GetObjectTaggingRequest(
    bucket: 'examplebucket',
    key: 'exampleobject.txt'
);

$result = $client->getObjectTagging($request);

// Print the tag set.
printf(
    'HTTP status: %s' . PHP_EOL .
    'Request ID: %s' . PHP_EOL .
    'Result: %s' . PHP_EOL,
    $result->statusCode,
    $result->requestId,
    var_export($result, true)
);

Replace examplebucket and exampleobject.txt with your actual bucket name and object name.

Parameters

ParameterRequiredTypeDescription
bucketYesstringThe name of the bucket that contains the object.
keyYesstringThe full name (path) of the object.

Response

A successful request returns HTTP status 200 and a result object with the following fields:

FieldTypeDescription
statusCodeintegerThe HTTP status code. 200 indicates success.
requestIdstringThe unique request ID for debugging and support.

What's next