嘿,我只是CURL的学习者,我正在通过这个新的Envato学习 API。我不知道我犯了什么错误,我可以获取代码,但无法使用https://build.envato.com/api#oauth中的POST方法调用
$ch = curl_init();
$url = 'https://api.envato.com/tokengrant_type=authorization_code&code='$_GET["code"]'&client_id=1&client_secret=MYSECRETKEY?type=post';
//makes the array suitable for sending
$items = http_build_query($member);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($members));
curl_setopt($ch, CURLOPT_POSTFIELDS, $items);
//execute
$result = curl_exec($ch);
//close curl session / free resources
curl_close($ch);
//ends
`
答案 0 :(得分:1)
您正在使用未定义的变量$member
,即未定义的值来填写POST正文。此外,您在URL中包含查询参数的参数应该是POST正文的一部分。这应该有效:
$ch = curl_init('https://api.envato.com/token');
$member = array(
'grant_type' => 'authorization_code',
'code' => $_GET["code"],
'client_id' => "1",
'client_secret' => 'MYSECRETKEY'
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($member));
$result = curl_exec($ch);
curl_close($ch);