Quantcast
Channel: Developer topics
Viewing all articles
Browse latest Browse all 17881

PowerBI create dataset response bad HTTP 400

$
0
0

Hello, anyone can help ? I don't know why  my  powerbi api creat dataset http response 400 does not working.

I  am following  the offical  provide  step doing and it's response bad http  400 why????? Where is problem i can't find ???http still 400

<?php
class powerbi{
  function config(){
	  $info = array(
	  'clintid'=>"6c20753d-28e9-4df4-b237-e5df37f2b85e",
	  'scrept'=>'AGRrAlhW6oJreVMNs55FeI6NlVB+8T12HghzBZW5a+8=',
	  'rdurl'=>"http://atline.com.tw/admin/Power_BI/get.php",
	  'sorcurl'=>"https://analysis.windows.net/powerbi/api",
	  'athorityurl'=>"https://login.windows.net/common/oauth2/authorize",
	  );
	  return $info;
  }
  function takon(){
	  $get_info = $this->config();
      foreach($get_info as $k=>$v){
		  $$k = $v;
	  }
	  $code = $_GET['code'];
      $session_state = $_GET['session_state'];
      $url = "https://login.windows.net/common/oauth2/token";
      $data = array(
      'grant_type'=>'authorization_code',
	  'client_id'=>$clintid,
	  'code'=>$code,
	  'redirect_uri'=>$rdurl,
	  'resource'=>$sorcurl,
	  'client_secret'=>$scrept
      );
	  $header[] = "Content-Type: application/x-www-form-urlencoded"; 
      $res  = $this->get_respond('post',$data,$header,$url);
	  $res = json_decode($res);
      return $res;
  }
  function creat_data_set(){
	session_start();
	$access = $this->takon();
	$token_type = $access->token_type;
    $token = $access->access_token;	
	date_default_timezone_set('UTC');
	$date = date('D , d M Y	H:i:s');
	//Sun, 20 Sep 2009 20:36:40 GMT
	$tablename = 'itistest';
	$columns[] = array(
	'name'=>'PorductID',
	'type'=>'Text',
	);
	$columns[] = array(
	'name'=>'Name',
	'type'=>'Text',
	);
	$columns[] = array(
	'name'=>'Number',
	'type'=>'Number',
	);
	$columns[] = array(
	'name'=>'Price',
	'type'=>'Number',
	);
	$columns[] = array(
	'name'=>'MenuId',
	'type'=>'Text',
	);
	$columns[] = array(
	'name'=>'PurchaseTime',
	'type'=>'DateTime',	
	);
	$columns[] = array(
	'name'=>'SPN',
	'type'=>'Text',	
	);
	$table = array(
	'name'=>$tablename,
	'columns'=>	$columns,
	);
	$data = array(
	'name'=>'Client',
	'table'=>$table,
	);

	$data = utf8_encode(json_encode($data));
	$url ="https://api.powerbi.com/v1.0/myorg/datasets";
	$header[] ="Authorization: $token_type $token";
	$header[] ="ContentType : application/json";
	$data = utf8_encode(json_encode($data));
	$res  = $this->get_respond('creat',$data,$header,$url);
	print_r($res);
  }
  function list_data(){
	  $url ="https://api.powerbi.com/v1.0/myorg/datasets";
	  $header[] ="Authorization: $token_type $token";
	  $res  = $this->get_respond('get','',$header,$url);
  }
  function report(){
  }
  function add_row(){
  }
  function get_respond($http,$data,$header,$url){       
	   $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $url);
       curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
	   curl_setopt($ch, CURLOPT_HEADER, false);
	   switch($http){
		   case"post":
			curl_setopt($ch, CURLOPT_POST, 1); 
			curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
	      break;
		  case"get":
		  break;
		  case"put":
		  break;
		  case"delete":
		  case"creat":
		   curl_setopt($ch, CURLOPT_POST, 1); 
	       curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
		  break;
		  break;
	   }
	   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	   $output = curl_exec($ch);
	   $htt_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
	   curl_close($ch);
	   if($htt_code>300||$htt_code<200){
		   echo $htt_code;
		   exit('操作失敗');
	   }
	 
	  return $output;
  }
}
$powerbinew = new powerbi();
$powerbinew->creat_data_set();


// great data set

 

my json code 

 

{"name":"Client","table":[{"name":"itistest","columns":[{"name":"PorductID","type":"Text"},{"name":"Name","type":"Text"},{"name":"Number","type":"Number"},{"name":"Price","type":"Number"},{"name":"MenuId","type":"Text"},{"name":"PurchaseTime","type":"DateTime"},{"name":"SPN","type":"Text"}]}]}

 


Viewing all articles
Browse latest Browse all 17881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>