Java için ApsaraVideo Live sunucu SDK'sını yükleyin ve kod örnekleriyle API işlemlerini çağırın.
Önkoşullar
ApsaraVideo Live API'lerini çağırma yetkisine sahip bir RAM kullanıcısı. RAM kullanıcısı oluşturun ve yetkilendirin.
Kimlik doğrulama için bir AccessKey çifti. AccessKey çifti oluşturun.
Java 1.8 veya sonraki sürümler.
SDK'yı kullanın
SDK'yı yükleyin
Aşağıdaki Maven bağımlılığını pom.xml dosyanıza ekleyin:
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-live20161101</artifactId>
<version>2.0.1</version>
</dependency>
Bir API işlemini çağırın
Aşağıdaki örnek, bir anlık görüntü yapılandırmasını sorgular.
// This file is auto-generated, don't edit it. Thanks.
package demo;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;
//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;
public class DescribeLiveSnapshotConfig {
public static void main(String[] args) throws Exception {
// HttpClient Configuration
/*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
.connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout. Default value: 10 seconds.
.responseTimeout(Duration.ofSeconds(10)) // Set the response timeout. Default value: 20 seconds.
.maxConnections(128) // Set the connection pool size.
.maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout. Default value: 30 seconds.
// Configure the proxy.
.proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
.setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
// For an HTTPS connection, you must configure a certificate or ignore the certificate by using .ignoreSSL(true).
.x509TrustManagers(new X509TrustManager[]{})
.keyManagers(new KeyManager[]{})
.ignoreSSL(false)
.build();*/
// Configure credentials.
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
// Ensure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
.accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
.accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
//.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use an STS token.
.build());
// Configure the client.
AsyncClient client = AsyncClient.builder()
.region("<Your RegionId>") // region ID
//.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
.credentialsProvider(provider)
//.serviceConfiguration(Configuration.create()) // Configure the service level.
// Override the client-level configuration to set parameters such as the endpoint and HTTP request parameters.
.overrideConfiguration(
ClientOverrideConfiguration.create()
// For a list of endpoints, see https://api.alibabacloud.com/product/live.
.setEndpointOverride("live.aliyuncs.com")
//.setConnectTimeout(Duration.ofSeconds(30))
)
.build();
// Set the parameters for the API request.
DescribeLiveSnapshotConfigRequest describeLiveSnapshotConfigRequest = DescribeLiveSnapshotConfigRequest.builder()
.domainName("<Your DomainName>")
.appName("<Your AppName>")
// Override the request-level configuration to set HTTP request parameters.
// .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
.build();
// Asynchronously get the API response.
CompletableFuture<DescribeLiveSnapshotConfigResponse> response = client.describeLiveSnapshotConfig(describeLiveSnapshotConfigRequest);
// Synchronously get the API response.
DescribeLiveSnapshotConfigResponse resp = response.get();
System.out.println(new Gson().toJson(resp));
// Asynchronously process the response.
/*response.thenAccept(resp -> {
System.out.println(new Gson().toJson(resp));
}).exceptionally(throwable -> { // Handle exceptions.
System.out.println(throwable.getMessage());
return null;
});*/
// Close the client.
client.close();
}
}
Açı parantezleri içindeki (
<...>) yer tutucu değerleri gerçek değerlerinizle değiştirin.<bölge ID>: hizmetinizin dağıtıldığı bölge. Geçerli değerler: Uç noktalar.<ALIBABA_CLOUD_ACCESS_KEY_ID>ve<ALIBABA_CLOUD_ACCESS_KEY_SECRET>: AccessKey çiftiniz. Önkoşullar.DescribeLiveSnapshotConfigRequest, anlık görüntü yapılandırmasını sorgulamak için kullanılan istek sınıfıdır.
DescribeLiveSnapshotConfigResponse, anlık görüntü yapılandırmasını sorgulamak için kullanılan yanıt sınıfıdır.
İstek ve yanıt parametreleri: DescribeLiveSnapshotConfig.
API çağrıları QPS sınırlamalarına tabidir. Akış kontrolü.
Yukarıdaki örnek, yanıtı bir DescribeLiveSnapshotConfigResponse nesnesine serileştirir. Ham HttpResponse nesnesini almak için bunun yerine doAction yöntemini çağırın.
HttpResponse httpResponse=client.doAction(describeLiveStreamSnapshotInfoRequest);
int status=httpResponse.getStatus();
Kullanım notları:
2xx: Çağrı başarılı oldu.
3xx veya 4xx: SDK bir ClientException özel durumu oluşturur.
5xx: SDK bir ServerException özel durumu oluşturur.
Gereksinimlerinize göre client.getAcsResponse veya client.doAction yöntemini seçin.
Adlandırma kuralı: [APIAdı]Request istek sınıfı, [APIAdı]Response ise yanıt sınıfı olarak adlandırılır.
Yaygın API işlemleri:
|
API |
İstek sınıfı |
Yanıt sınıfı |
|
DescribeLiveSnapshotConfig |
DescribeLiveSnapshotConfig |
|
|
AddLiveAppRecordConfig |
AddLiveAppRecordConfig |
|
|
DescribeLiveRecordConfig |
DescribeLiveRecordConfig |
|
|
AddLiveStreamTranscode |
AddLiveStreamTranscode |
|
|
DescribeLiveStreamTranscodeInfo |
DescribeLiveStreamTranscodeInfo |
|
|
BatchSetLiveDomainConfigs |
BatchSetLiveDomainConfigs |
|
|
DescribeLiveDomainConfigs |
DescribeLiveDomainConfigs |
|
|
Mevcut tüm API işlemleri hakkında bilgi için bkz. API genel bakış. |
||
Erişim kontrolü
Her API işlemi yetkilendirme bilgileri içerir. Örneğin, AddLiveAppSnapshotConfig işlemi aşağıdaki ayrıntılara sahiptir.
Eylem: live:AddLiveAppSnapshotConfig. Erişim düzeyi: create. Kaynak türü: Domain. ARN biçimi: acs:cdn:*:{#accountId}:domain/{#DomainName}. Koşul anahtarı veya ilişkili işlem bulunmamaktadır.
Bir RAM kullanıcısını belirli bir etki alanıyla sınırlamak gibi daha ayrıntılı erişim kontrolü sağlamak için bir özel ilke oluşturun.
Her işlem için erişim kontrolü ayrıntıları: RAM yetkilendirmesi.