我根据Instagram API文档使用服务器端流程对Instagram用户进行身份验证。一旦用户成功验证并授权我的应用程序,API就会向redirect_uri返回一个“代码”,然后我会交换一个访问令牌。当我在HTML标记中启动以下过程时,所有这一切都正常。我想用curl GET请求替换标记,我认为该请求与具有method =“GET”的表单提交相同。我从curl请求收到一个http_code = 200的响应头但是我没有收到我提交表单时收到的响应数据包。我的curl请求有什么问题,或者我错误地认为curl GET请求的行为与GET表单相同。
HTML markup:
<div id="instagramConnect">
<form id="instagram-signin"
action="<?php echo($i->instagram_arr['authorize_url']) ?>" method="GET">
<input type="hidden" name="client_id"
value="<?php echo($i->instagram_arr['client_id']) ?>" />
<input type="hidden" name="redirect_uri"
value="<?php echo ($i->instagram_arr['redirect_uri']) ?>" />
<input type="hidden" name="response_type" value="code" />
<input type="submit" id="instagram-submit" value="Signin to Instagram"></input>
</form>
</div>
Would like to replace markup with this curl:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_URL =>
$i->instagram_arr["authorize_url"].
'?client_id='.$i->instagram_arr["client_id"].
'&redirect_uri='.$i->instagram_arr["redirect_uri"].
'&response_type=code'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
$err = curl_errno ( $curl );
$errmsg = curl_error ( $curl );
$header = curl_getinfo ( $curl);
$httpCode = curl_getinfo ( $curl, CURLINFO_HTTP_CODE );
print_r($httpCode); //returns 200
echo $resp; //should be an access code but nothing
}