搜索相关性得分器API

时间:2016-03-30 12:20:11

标签: php

我正在使用有效的API KEY运行此代码,但它显示错误消息,例如

string(179) "{"error":{"code":"Unauthorized","message":"Request is unauthorized to access resource.","details":[{"code":"ScoreRequestUnauthorized","message":"Invalid credentials provided."}]}}"

我在R语言中使用相同的API Key并且工作正常。这可能是HEADER参数不正确的原因。

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$url = 'https://ussouthcentral.services.azureml.net/workspaces/d90e4daf20ce4d28a03a802fcd423f88/services/21c5bf104ffc4528932603b5e71fbc9f/execute?api-version=2.0&details=true';

$data = array(
  'Inputs'=> array(
      'input1'=> array(
          'ColumnNames' => array("query", "p1", "p2", "p3", "p4", "p5"),
          'Values' => array( array("value1" ,  "value2" ,  "value3"),array("bags", "bags", "bags", "bags"))
      )
  ),
  'GlobalParameters'=> null
);           


$body = json_encode($data);
$api_key = 'API-KEY'; 
$headers = array('Content-Type: application/json', 'Authorization: Bearer '.$api_key, 'Accept: application/json');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response  = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>

这是正确的代码

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$url = 'https://ussouthcentral.services.azureml.net/workspaces/d90e4daf20ce4d28a03a802fcd423f88/services/21c5bf104ffc4528932603b5e71fbc9f/execute?api-version=2.0&details=true';

$data = array(
            'Inputs'=> array(
                'input1'=> array(
                    'ColumnNames' => array("query", "p1", "p2", "p3", "p4", "p5"),
                    'Values' => array( array("bags", "bags", "bags", "bags", "bags", "bags"),array("bags", "bags", "bags", "bags", "bags", "bags"))
                    )
                ),
            'GlobalParameters'=> null
            );           

$body = json_encode($data);
$api_key = 'API-KEY'; 
$headers = array('Content-Type: application/json', 'Authorization: Bearer '.$api_key, 'Accept: application/json');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response  = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>

1 个答案:

答案 0 :(得分:0)

这是正确的代码     

plotOptions: {
        series: {
            marker: {
                enabled: true

            }
        }
    },