Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有内容配置的PHP cURL:表单数据_Php_Api_Curl - Fatal编程技术网

带有内容配置的PHP cURL:表单数据

带有内容配置的PHP cURL:表单数据,php,api,curl,Php,Api,Curl,在将Instagram cURL转换为PHP时,我对它感到困惑,请参见以下内容: curl -F 'client_id=CLIENT_ID' \ -F 'client_secret=CLIENT_SECRET' \ -F 'grant_type=authorization_code' \ -F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \ -F 'code=CODE' \ https://api.instag

在将Instagram cURL转换为PHP时,我对它感到困惑,请参见以下内容:

   curl -F 'client_id=CLIENT_ID' \
    -F 'client_secret=CLIENT_SECRET' \
    -F 'grant_type=authorization_code' \
    -F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \
    -F 'code=CODE' \
    https://api.instagram.com/oauth/access_token  
这是我当前的代码,有一个错误

{
  "error_type": "OAuthException",
  "code": 400,
  "error_message": "You must provide a client_id"
}
具有样本值的当前代码:

$client_id = "7d60c47cdwe249069cdb07a0f28e19cb";
$client_secret = "de5awwe3ebf1443d8dcf0fbc88e5ab1b";
$grant_type = "authorization_code";
$redirect_uri = "http://sexample.net/create-code.php";
$code ="y23d86c19b4c3b0a8b561e64c93f2b3f";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    //format URL to grant access to email and sitename passed
    $data  = '{"client_id":"'.$client_id.'","client_secret":"'.$client_secret.'","grant_type":"'.$grant_type.'","redirect_uri":"'.$redirect_uri.'","code":"'.$code.'"}';
    curl_setopt($ch, CURLOPT_URL, 'https://api.instagram.com/oauth/access_token');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    //execute cURL call and get template data
    $output = curl_exec($ch);
    curl_close($ch);
    echo $output;