Monday, August 22, 2016

How to integrate IBM bluemix personality insight service using php Api

Hi Everyone, I need to share IBM Bluemix service  "Personality Insight" integration using PHP , I do not want to waste the time in RND for anyone which I have wasted. because I could not found complete help from google and finally consolidate all of my code . so  please follow below instruction to easily integration with Ibm tool.

Step1-> Create a free trail account on IBM Bluemix
 and then go to your email inbox which email id you registered the click the activation link then login into IBM Bluemix.

Step-> After login then click on dashboard on  top menu and create SPACE enter following input .

Step3-> Go to the dashboad  then Console->Service->Watson ->Pesonality Insight .



Step4->Add the Personal Insight entering below infromation



Step-> Let side menu get the Pesonality Insight API Credentials following below step

 


 Finally integration IBM Bluemix service "Personality Insight" with PHP below code using curl function.


###################API CALL USING CURL PHP############################
            //IBM Bluemix Pesonal Insite service username
             $username='a2c41634-21e3-485e-b84d-98192819fcc0';
             //IBM Bluemix Pesonal Insite service password
             $password='KafbLpudysBZ';
             $data="Mor than 100 words user profile data";
             $curl = curl_init();
     
               $ciarr = array(
    "contentItems" =>  array(
                        "userid" => "dummyuserid",
                        "id" => "dummyid",
                        "sourceid" => "freetext",
                        "contenttype" => "application/json",
                        "language" => "en",
                        "content" => $data
                  )
              );



                $ciroot = array("contentItems" => $ciarr);
                $data_str=json_encode($ciarr);   
                curl_setopt($curl, CURLOPT_POST, true); 
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data_str);
                curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
                curl_setopt($curl, CURLOPT_URL, "https://gateway.watsonplatform.net/personality-insights/api/v2/profile");
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_HTTPHEADER,
              array(
                'Content-Type: text/plain',
                'Content-Length: ' . strlen($data_str)

                ));
       
               $result = curl_exec($curl);      
               curl_close($curl);     
               $decoded = json_decode($result, true);     
               return $result;

##########################Write JSON#######################################


        $fp = fopen('resources/profile.json', 'w');
        fwrite($fp, $res);
        fclose($fp);
##########################Call chart JS function ##################################
/* call graph chart personality insight interface function  after include JS*/
      $.getJSON('./resources/profile.json', '', function ( profile )
      {

            //$('#profile').append('<pre>' + JSON.stringify(profile, null, 2) + '</pre>');
            var chart = new PersonalitySunburstChart('sunburstChart');
            chart.show(profile, './resources/profile_photo.jpg');


      });
#######################OUT PUT#############################












Hope it will help you click to full download ->
-------------------------------------------------------------
if you think it would be helpfulplease donate few amount to
improved my blog and free to post.
using below button -------------------------------------------------------------

Wednesday, April 27, 2016

Custom download to excel using php


 <?php
 $content="<table><tr><td style='color:red;background-color:green;'>created by bikash</td></tr></table>";

$downloadFileName = 'test_report_'.time().'.xls';
 $filename = SITE_PATH_SPDATA."xml_data/reports/$downloadFileName";
 header("Cache-Control: no-store, no-cache, must-revalidate");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
 header("Content-Type: application/vnd.ms-excel");
 header("Content-Length: strlen($achDowloadContent)");
 header("Content-Disposition:; filename=$downloadFileName");
 echo $contents;

?>