【问题标题】:PHP Personality InsightsPHP 个性洞察
【发布时间】:2016-09-11 13:59:58
【问题描述】:
<?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 我错过了什么?我应该如何设置这个变量,我应该如何传递我想要分析的文本?

【问题讨论】:

    标签: php curl ibm-cloud personality-insights


    【解决方案1】:

    在这个 php 代码中,您只需分配给 $post_args['body'] 的变量是 $data。我认为你在提交的帖子中使用,所以如果你从 url 得到的东西比

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

    或者如果你发送到 url 就设置一些值

    $data = 'Your real data which you want to send in url  ' ; than use in array .
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多