telnyx-webrtc-java
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
Telnyx Webrtc - Java
Telnyx Webrtc - Java
Installation
安装
text
<!-- Maven -->
<dependency>
<groupId>com.telnyx.sdk</groupId>
<artifactId>telnyx</artifactId>
<version>6.36.0</version>
</dependency>
// Gradle
implementation("com.telnyx.sdk:telnyx:6.36.0")text
<!-- Maven -->
<dependency>
<groupId>com.telnyx.sdk</groupId>
<artifactId>telnyx</artifactId>
<version>6.36.0</version>
</dependency>
// Gradle
implementation("com.telnyx.sdk:telnyx:6.36.0")Setup
配置
java
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
TelnyxClient client = TelnyxOkHttpClient.fromEnv();All examples below assume is already initialized as shown above.
clientjava
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
TelnyxClient client = TelnyxOkHttpClient.fromEnv();以下所有示例均假设已按照上方代码完成初始化。
clientError Handling
错误处理
All API calls can fail with network errors, rate limits (429), validation errors (422),
or authentication errors (401). Always handle errors in production code:
java
import com.telnyx.sdk.errors.TelnyxServiceException;
try {
var result = client.messages().send(params);
} catch (TelnyxServiceException e) {
System.err.println("API error " + e.statusCode() + ": " + e.getMessage());
if (e.statusCode() == 422) {
System.err.println("Validation error — check required fields and formats");
} else if (e.statusCode() == 429) {
// Rate limited — wait and retry with exponential backoff
Thread.sleep(1000);
}
}Common error codes: invalid API key, insufficient permissions,
resource not found, validation error (check field formats),
rate limited (retry with exponential backoff).
401403404422429所有API调用都可能出现网络错误、速率限制(429)、校验错误(422)或鉴权错误(401),生产环境代码中务必处理这些错误:
java
import com.telnyx.sdk.errors.TelnyxServiceException;
try {
var result = client.messages().send(params);
} catch (TelnyxServiceException e) {
System.err.println("API error " + e.statusCode() + ": " + e.getMessage());
if (e.statusCode() == 422) {
System.err.println("Validation error — check required fields and formats");
} else if (e.statusCode() == 429) {
// Rate limited — wait and retry with exponential backoff
Thread.sleep(1000);
}
}常见错误码: API密钥无效, 权限不足, 资源不存在, 校验错误(请检查字段格式), 触发速率限制(请使用指数退避策略重试)。
401403404422429Important Notes
重要说明
- Pagination: List methods return a page. Use for automatic iteration:
.autoPager(). For manual control, usefor (var item : page.autoPager()) { ... }and.hasNextPage()..nextPage()
- 分页: 列表方法返回单页数据。如需自动遍历可使用:
.autoPager()。如需手动控制,可使用for (var item : page.autoPager()) { ... }和.hasNextPage()方法。.nextPage()
List mobile push credentials
列出移动推送凭证
GET /mobile_push_credentialsjava
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialListPage;
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialListParams;
MobilePushCredentialListPage page = client.mobilePushCredentials().list();Returns: (string), (string), (date-time), (string), (string), (object), (string), (string), (date-time)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atGET /mobile_push_credentialsjava
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialListPage;
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialListParams;
MobilePushCredentialListPage page = client.mobilePushCredentials().list();返回参数:(字符串)、(字符串)、(日期时间)、(字符串)、(字符串)、(对象)、(字符串)、(字符串)、(日期时间)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atCreates a new mobile push credential
创建新的移动推送凭证
POST /mobile_push_credentialstypecertificateprivate_keyaliasjava
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialCreateParams;
import com.telnyx.sdk.models.mobilepushcredentials.PushCredentialResponse;
MobilePushCredentialCreateParams.CreateMobilePushCredentialRequest.Ios params = MobilePushCredentialCreateParams.CreateMobilePushCredentialRequest.Ios.builder()
.alias("LucyIosCredential")
.certificate("-----BEGIN CERTIFICATE----- MIIGVDCCBTKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END CERTIFICATE-----")
.privateKey("-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END RSA PRIVATE KEY-----")
.build();
PushCredentialResponse pushCredentialResponse = client.mobilePushCredentials().create(params);Returns: (string), (string), (date-time), (string), (string), (object), (string), (string), (date-time)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atPOST /mobile_push_credentialstypecertificateprivate_keyaliasjava
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialCreateParams;
import com.telnyx.sdk.models.mobilepushcredentials.PushCredentialResponse;
MobilePushCredentialCreateParams.CreateMobilePushCredentialRequest.Ios params = MobilePushCredentialCreateParams.CreateMobilePushCredentialRequest.Ios.builder()
.alias("LucyIosCredential")
.certificate("-----BEGIN CERTIFICATE----- MIIGVDCCBTKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END CERTIFICATE-----")
.privateKey("-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END RSA PRIVATE KEY-----")
.build();
PushCredentialResponse pushCredentialResponse = client.mobilePushCredentials().create(params);返回参数:(字符串)、(字符串)、(日期时间)、(字符串)、(字符串)、(对象)、(字符串)、(字符串)、(日期时间)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atRetrieves a mobile push credential
查询单个移动推送凭证
Retrieves mobile push credential based on the given
push_credential_idGET /mobile_push_credentials/{push_credential_id}java
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialRetrieveParams;
import com.telnyx.sdk.models.mobilepushcredentials.PushCredentialResponse;
PushCredentialResponse pushCredentialResponse = client.mobilePushCredentials().retrieve("0ccc7b76-4df3-4bca-a05a-3da1ecc389f0");Returns: (string), (string), (date-time), (string), (string), (object), (string), (string), (date-time)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_at根据传入的查询对应的移动推送凭证
push_credential_idGET /mobile_push_credentials/{push_credential_id}java
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialRetrieveParams;
import com.telnyx.sdk.models.mobilepushcredentials.PushCredentialResponse;
PushCredentialResponse pushCredentialResponse = client.mobilePushCredentials().retrieve("0ccc7b76-4df3-4bca-a05a-3da1ecc389f0");返回参数:(字符串)、(字符串)、(日期时间)、(字符串)、(字符串)、(对象)、(字符串)、(字符串)、(日期时间)
aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atDeletes a mobile push credential
删除移动推送凭证
Deletes a mobile push credential based on the given
push_credential_idDELETE /mobile_push_credentials/{push_credential_id}java
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialDeleteParams;
client.mobilePushCredentials().delete("0ccc7b76-4df3-4bca-a05a-3da1ecc389f0");根据传入的删除对应的移动推送凭证
push_credential_idDELETE /mobile_push_credentials/{push_credential_id}java
import com.telnyx.sdk.models.mobilepushcredentials.MobilePushCredentialDeleteParams;
client.mobilePushCredentials().delete("0ccc7b76-4df3-4bca-a05a-3da1ecc389f0");List all credentials
列出所有凭证
List all On-demand Credentials.
GET /telephony_credentialsjava
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialListPage;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialListParams;
TelephonyCredentialListPage page = client.telephonyCredentials().list();Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id列出所有按需凭证。
GET /telephony_credentialsjava
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialListPage;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialListParams;
TelephonyCredentialListPage page = client.telephonyCredentials().list();返回参数:(字符串)、(布尔值)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idCreate a credential
创建凭证
Create a credential.
POST /telephony_credentialsconnection_idOptional: (string), (string), (string)
expires_atnametagjava
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialCreateParams;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialCreateResponse;
TelephonyCredentialCreateParams params = TelephonyCredentialCreateParams.builder()
.connectionId("1234567890")
.build();
TelephonyCredentialCreateResponse telephonyCredential = client.telephonyCredentials().create(params);Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id创建一个凭证。
POST /telephony_credentialsconnection_id可选参数:(字符串)、(字符串)、(字符串)
expires_atnametagjava
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialCreateParams;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialCreateResponse;
TelephonyCredentialCreateParams params = TelephonyCredentialCreateParams.builder()
.connectionId("1234567890")
.build();
TelephonyCredentialCreateResponse telephonyCredential = client.telephonyCredentials().create(params);返回参数:(字符串)、(布尔值)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idGet a credential
查询单个凭证
Get the details of an existing On-demand Credential.
GET /telephony_credentials/{id}java
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialRetrieveParams;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialRetrieveResponse;
TelephonyCredentialRetrieveResponse telephonyCredential = client.telephonyCredentials().retrieve("550e8400-e29b-41d4-a716-446655440000");Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id查询已存在的按需凭证的详情。
GET /telephony_credentials/{id}java
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialRetrieveParams;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialRetrieveResponse;
TelephonyCredentialRetrieveResponse telephonyCredential = client.telephonyCredentials().retrieve("550e8400-e29b-41d4-a716-446655440000");返回参数:(字符串)、(布尔值)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idUpdate a credential
更新凭证
Update an existing credential.
PATCH /telephony_credentials/{id}Optional: (string), (string), (string), (string)
connection_idexpires_atnametagjava
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialUpdateParams;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialUpdateResponse;
TelephonyCredentialUpdateResponse telephonyCredential = client.telephonyCredentials().update("550e8400-e29b-41d4-a716-446655440000");Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id更新已存在的凭证。
PATCH /telephony_credentials/{id}可选参数:(字符串)、(字符串)、(字符串)、(字符串)
connection_idexpires_atnametagjava
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialUpdateParams;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialUpdateResponse;
TelephonyCredentialUpdateResponse telephonyCredential = client.telephonyCredentials().update("550e8400-e29b-41d4-a716-446655440000");返回参数:(字符串)、(布尔值)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idDelete a credential
删除凭证
Delete an existing credential.
DELETE /telephony_credentials/{id}java
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialDeleteParams;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialDeleteResponse;
TelephonyCredentialDeleteResponse telephonyCredential = client.telephonyCredentials().delete("550e8400-e29b-41d4-a716-446655440000");Returns: (string), (boolean), (string), (string), (string), (string), (string), (string), (string), (string), (string)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id删除已存在的凭证。
DELETE /telephony_credentials/{id}java
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialDeleteParams;
import com.telnyx.sdk.models.telephonycredentials.TelephonyCredentialDeleteResponse;
TelephonyCredentialDeleteResponse telephonyCredential = client.telephonyCredentials().delete("550e8400-e29b-41d4-a716-446655440000");返回参数:(字符串)、(布尔值)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)、(字符串)
created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id