这是我使用API从翻转卡丁车中检索数据的curl,php程序。但是,无论我做什么,我都会得到同样的错误:
{“error”:“unauthorized”,“error_description”:“在SecurityContext中找不到身份验证对象”}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.flipkart.net/oauth-service/oauth/token?grant_type=client_credentials&scope=Seller_Api,Default");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'appid:appsecret';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
print $server_output ;
curl_close ($ch);
?>
我不知道错误是什么,我检查了问题的时间,如果问题是appid和appsecret我给了但仍然显示相同的错误。
答案 0 :(得分:0)
$action = 'https://sandbox-api.flipkart.net/oauth-service/oauth/token?grant_type=client_credentials&scope=Seller_Api';
$headers = array();
$headers[] = 'content-type: application/json';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $action);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, "<id>:<key>");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
$result = curl_exec($curl);
echo '<pre>';print_r($result);
curl_close($curl);