Описание
Возвращает количество Telegram Stars, которыми владеет управляемый бизнес-аккаунт. Требует права бизнес-бота can_view_gifts_and_stars. При успехе возвращает StarAmount.
| Параметр | Тип | Обязательный | Описание |
|---|---|---|---|
| business_connection_id | String | Да | Уникальный идентификатор бизнес-подключения |
Примеры
php
<?php
$botToken = 'YOUR_BOT_TOKEN';
$businessConnectionId = 'YOUR_BUSINESS_CONNECTION_ID';
$apiUrl = "https://api.telegram.org/bot{$botToken}/getBusinessAccountStarBalance";
$postData = [
'business_connection_id' => $businessConnectionId
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
} else {
$responseData = json_decode($response, true);
if ($responseData['ok']) {
$starAmount = $responseData['result'];
echo "Star balance: " . $starAmount['star_count'] . " stars\n";
echo "Equivalent in USD: $" . $starAmount['usd_amount'] . "\n";
} else {
echo "Error: " . $responseData['description'] . "\n";
}
}
curl_close($ch);
// Альтернативный вариант с использованием file_get_contents
/*
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/json\r\n",
'content' => json_encode($postData)
]
]);
$response = file_get_contents($apiUrl, false, $context);
$responseData = json_decode($response, true);
if ($responseData['ok']) {
$starAmount = $responseData['result'];
echo "Star balance: " . $starAmount['star_count'] . " stars\n";
echo "Equivalent in USD: $" . $starAmount['usd_amount'] . "\n";
} else {
echo "Error: " . $responseData['description'] . "\n";
}
*/
?>
python
import requests
def get_business_account_star_balance(bot_token, business_connection_id):
"""
Returns the amount of Telegram Stars owned by a managed business account.
Args:
bot_token (str): Your bot's token
business_connection_id (str): Unique identifier of the business connection
Returns:
dict: JSON response containing StarAmount on success
"""
url = f"https://api.telegram.org/bot{bot_token}/getBusinessAccountStarBalance"
payload = {
"business_connection_id": business_connection_id
}
response = requests.post(url, json=payload)
return response.json()
# Пример использования
if __name__ == "__main__":
# Замените на ваш токен бота
BOT_TOKEN = "YOUR_BOT_TOKEN"
# Замените на ID бизнес-подключения
BUSINESS_CONNECTION_ID = "your_business_connection_id"
try:
result = get_business_account_star_balance(BOT_TOKEN, BUSINESS_CONNECTION_ID)
print(result)
if result.get("ok"):
star_amount = result.get("result", {})
print(f"Баланс Stars: {star_amount.get('star_count')}")
else:
print(f"Ошибка: {result.get('description')}")
except Exception as e:
print(f"Произошла ошибка: {e}")
История изменений
- API 9.0. Добавлен метод getBusinessAccountStarBalance
Дополнительно
- StarAmount - Объект для представления количества Telegram Stars с поддержкой дробных значений.