Q:

Unable to get access token from azure media services REST API using PHP

I have the following code in php:
define("TOKEN_URL", "https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13");

 $arrData = array(
                'grant_type=client_credentials',
                'client_id='. CLIENT_ID,
                'client_secret='.urlencode(ACCESS_KEY),
                'scope=urn%3aWindowsAzureMediaServices'
            );

            $arrHeader = array(
                'Content-length:'.strlen($this->generateData($arrData))
            );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TOKEN_URL);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->generateData($arrData));
            curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $data = curl_exec($ch);
            curl_close($ch);
            $arrToken = json_decode($data);

I am unable to get the token code.  Please can anyone check what could be wrong?  

A:

There could be a few issues:

You could simplify a few things and use http_build_query():
$data = http_build_query(array(
    'grant_type' => 'client_credentials',
    'client_id' => CLIENT_ID,
    'client_secret' => ACCESS_KEY,
    'scope' => 'urn:WindowsAzureMediaServices',
));
$ch = curl_init(TOKEN_URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (($res = curl_exec($ch)) === false) {
    die(curl_error($ch));
}
$arrToken = json_decode($res);

If there's an error, the first thing to make sure is whether you have an updated list of CA certificates.