猿问

Azure 媒体服务、带有 V3 api 和 ODataQuery 的 GetLocators

我正在尝试使用 v3 API 和Microsoft.Azure.Management.Media包获取给定资产的所有流式定位器,但使用 Odata 查询时出现错误请求错误:


它在这一行失败:var locator = client.StreamingLocators.List("webinars", "webinars", new ODataQuery<StreamingLocator>(x=>x.AssetName == assetId));


Microsoft.Azure.Management.Media.Models.ApiErrorException: Operation returned an invalid status code 'BadRequest'

当我在没有 ODataQuery 的情况下使用它时,它返回正常。


public IList<string> GetLocatorForAsset() {

            var assetId = "bb4953cf-4793-4b3c-aed8-ae1bec88a339";

            IList<string> streamingUrls = new List<string>();      


            var locator = client.StreamingLocators.List("webinars", "webinars", new ODataQuery<StreamingLocator>(x=>x.AssetName == assetId));

            ListPathsResponse paths = client.StreamingLocators.ListPaths("webinars", "webinars", locator.FirstOrDefault().Name);


            foreach (StreamingPath path in paths.StreamingPaths) {

                UriBuilder uriBuilder = new UriBuilder();

                uriBuilder.Scheme = "https";

                uriBuilder.Host = "webinars-use2.streaming.media.azure.net";


                uriBuilder.Path = path.Paths[0];

                streamingUrls.Add(uriBuilder.ToString());

            }


            return streamingUrls;


        }

    }


尚方宝剑之说
浏览 80回答 1
1回答

喵喵时光机

根据媒体服务过滤文档,用户只能通过“name”、“properties.created”和“properties.endTime”过滤“Streaming Locators”。https://learn.microsoft.com/en-us/azure/media-services/latest/entities-overview#streaming-locators在您的示例中,您尝试使用不支持的assetId/assetName 进行过滤。因此 400 Bad request 错误。请参阅邮递员中的详细错误示例这是使用流式定位器“名称”标签的有效过滤示例。注意:这不是资产标签用于使用“名称”成功过滤流式定位器的 C# 示例&nbsp; &nbsp; try&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; // GUID need to be specified in single quote. using OData v 3.0&nbsp; &nbsp; &nbsp; &nbsp; var odataquery = new ODataQuery<StreamingLocator>("name eq '65a1cb0d-ce7c-4470-93ac-fedf66450ea0'");&nbsp; &nbsp; &nbsp; &nbsp; IPage<StreamingLocator> locators = client.StreamingLocators.List("mediatest", "mymediatestaccount", odataquery);&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(locators.FirstOrDefault().Name);&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(locators.FirstOrDefault().StreamingLocatorId);&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(locators.FirstOrDefault().Id);&nbsp; &nbsp; &nbsp; &nbsp; ListPathsResponse paths = client.StreamingLocators.ListPaths("mediatest", "mymediatestaccount", locators.FirstOrDefault().Name);&nbsp; &nbsp; &nbsp; &nbsp; foreach (StreamingPath path in paths.StreamingPaths)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UriBuilder uriBuilder = new UriBuilder();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uriBuilder.Scheme = "https";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uriBuilder.Host = "webinars-use2.streaming.media.azure.net";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uriBuilder.Path = path.Paths[0];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(uriBuilder.ToString());&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; catch (Exception ex)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(ex.ToString());&nbsp; &nbsp; }我希望这有帮助。
随时随地看视频慕课网APP
我要回答