Eksportér (0) Udskriv
Udvid alt
EN
Dette indhold er ikke tilgængeligt på dit sprog, men her er den engelske version.
1 ud af 2 klassificerede dette som nyttigt - Bedøm dette emne

Connecting to Media Services with the Media Services REST API

Updated: April 8, 2014

Two things are required when accessing Windows Azure Media Services: An access token provided by Azure Access Control Services (ACS), and the URI of Media Services itself. You can use any means you want when creating these requests as long as you specify the correct header values and pass in the access token correctly when calling into Media Services.

ImportantImportant
After successfully connecting to https://media.windows.net, you will receive a 301 redirect specifying another Media Services URI. You must make subsequent calls to the new URI.

Getting an access token

To access Media Services directly through the REST API, retrieve an access token from ACS and use it during every HTTP request you make into the service. This token is similar to other tokens provided by ACS based on access claims provided in the header of an HTTP request and using the OAuth v2 protocol. You do not need any other prerequisites before directly connecting to Media Services.

The following example shows the HTTP request header and body used to retrieve a token:

POST https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: wamsprodglobal001acs.accesscontrol.windows.net
Content-Length: 120
Expect: 100-continue
Connection: Keep-Alive

grant_type=client_credentials&client_id=client id value&client_secret=URL-encoded client secret value&scope=urn%3aWindowsAzureMediaServices

ImportantImportant
The client_id and client_secret are provided to you by Media Services when you set up your account. They correspond to the AccountName and AccountKey values, respectively. For more information, see the Media Services account setup instructions. Also, the AccountKey for your Media Services account must be URL-encoded when using it as the client_secret value in your access token request.

The following example shows the HTTP response that contains the access token in the response body.

HTTP/1.1 200 OK
Cache-Control: public, no-store, max-age=0
Content-Type: application/json; charset=utf-8
Expires: Fri, 13 Jan 2012 22:40:07 GMT
Last-Modified: Fri, 13 Jan 2012 22:40:07 GMT
Vary: *
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=w3mtu2rnxucaz5tvj0iyfm0t; path=/; HttpOnly
X-AspNetMvc-Version: 2.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Content-Type-Options: nosniff
Date: Fri, 13 Jan 2012 22:40:07 GMT
Content-Length: 580

{"access_token":"http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=client_id&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1326498007&Issuer=https%3a%2f%2f wamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=hV1WF7sTe%2ffoHqzK%2ftmnwQY22NRPaDytcOOpC9Nv4DA%3d","token_type":"http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0","expires_in":"3599","scope":"urn:WindowsAzureMediaServices"}

ImportantImportant
It is recommended to cache the "access_token " and "expires_in " values to an external storage. The token data could later be retrieved from the storage and re-used in your Media Services REST API calls. This is especially useful for scenarios where the token can be securely shared among multiple processes or computers.

Make sure to monitor the "expires_in" value of the access token and update your REST API calls with new tokens as needed.

Connecting to the Media Services URI

The root URI for Media Services is https://media.windows.net/. You should initially connect to this URI, and if you get a 301 redirect back in response, you should make subsequent calls to the new URI. In addition, do not use any auto-redirect/follow logic in your requests. HTTP verbs and request bodies will not be forwarded to the new URI.

The root URI for uploading and downloading Asset files is https://yourstorageaccount.blob.core.windows.net/ where the storage account name is the same one you used during your Media Services account setup.

The following code example shows how to create an Asset in Media Services. Note the actual authorization mechanism that is passed in the request header is an OAuth v2 bearer token.

POST https://media.windows.net/API/Assets HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1335602357&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=XQs5T%2fEfdO39%2f0Z9%2fBBkA12%2bbUUEY21YyefWXuRYZlY%3d
Host: media.windows.net
Content-Length: 27
Expect: 100-continue

{ "Name" : "NewJSONAsset" }
TipTip
To make Media Services entities more discoverable, the $metadata operation can be used. It allows you to retrieve all valid entity types, entity properties, associations, functions, actions, and so on. The following example shows how to construct the URI: https://media.windows.net/API/$metadata.

You should append "?api-version=2.5" to the end of the URI if you want to view the metadata in a browser, or did not include the x-ms-version header in your request.

See Also


Build Date:

2014-04-10
Syntes du, dette var nyttigt?
(1500 tegn tilbage)
Tak for din feedback

Fællesskabsindhold

Tilføj
Vis:
© 2014 Microsoft. Alle rettigheder forbeholdes.