<?php
$curl = curl_init();
$post_args = array('body' => $data );
$header_args = array(
'Content-Type: text/plain',
'Accept: application/json'
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_args);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header_args);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD,"'xxx':'xxx'");
curl_setopt($curl, CURLOPT_URL, "https://gateway.watsonplatform.net/personality-insights/api/v2/profile");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close($curl);
$decoded = json_decode($result, true);
?>
我想在php curl中使用IBM Bluemix Personality Insights,我收到此错误:Undefined variable: data
我错过了什么?我该如何设置这个变量,我应该如何传递我想要分析的文本?
答案 0 :(得分:1)
在这个PHP代码中,您只需分配给$data
的{{1}}变量。我认为你在邮政领域使用,所以如果你从网址得到的东西比
$post_args['body']
或者只是在发送到网址时设置一些值
$post_args = array('body' => $_POST['data']) ;