0
<?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);
     ?>

我想将 IBM Bluemix Personality Insights 与 php curl 结合使用,但出现此错误:Undefined variable: data我错过了什么?我应该如何设置这个变量,我应该如何传递我想要分析的文本?

4

1 回答 1

1

在这个 php 代码中,$data您刚刚分配给的变量是什么$post_args['body']。我认为你在提交的帖子中使用,所以如果你从 url 得到一些东西,那就试试吧

$post_args = array('body' => $_POST['data']) ; 

或者如果您发送到 url,则只需设置一些值

$data = 'Your real data which you want to send in url  ' ; than use in array .
于 2016-09-11T14:47:03.793 回答