我试图获得我的长期存取令牌"使用CURL / PHP但我收到错误"缺少client_id,client_secret,code,grant_type,redirect_uri"的参数。
我打电话的网址是您可以清楚看到我试图传入的参数的地方!
https://api.surveymonkey.net/oauth/token?client_secret=' .urlencode($ client_secret)'&安培;代码=' .urlencode($ short_token)'&安培; REDIRECT_URI =' .urlencode($ REDIRECT_URL)'&安培; CLIENT_ID =' .urlencode($ CLIENT_ID)'&安培; grant_type = authorization_code
我还使用" application / x-www-form-urlencoded"的内容类型。根据文档(见下文)。
我的CURL请求:
function survey_monkey_curl_request($url, $params=[], $request_type = 'get', $access_token) {
print_r($url);
$ch = curl_init();
$headers = [
"Content-Type: application/x-www-form-urlencoded",
"Authorization: bearer " .$access_token
];
$opts = [
CURLOPT_URL => $url,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
];
if ($request_type == 'post') {
$opts[CURLOPT_POST] = 1;
//$opts[CURLOPT_POSTFIELDS] = json_encode($params);
}
if ($request_type == 'patch') {
$opts[CURLOPT_CUSTOMREQUEST] = "PATCH";
$opts[CURLOPT_POSTFIELDS] = json_encode($params);
}
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
if ($result === false) {
curl_close($ch);
throw new Exception(curl_error($ch));
}
curl_close($ch);
return $result;
}
我哪里错了?
答案 0 :(得分:2)
直接从文档中看起来,您需要获得发布字段所需的长期令牌:
x, y, z
https://developer.surveymonkey.com/api/v3/?shell#new-authentication
当您将参数附加到您的网址上时,您将作为GET请求参数发送
您需要将数据字符串放入CURL POSTFIELDS并且不要将json编码
PHP答案
//Exchange for long-lived token
curl -i -X POST https://api.surveymonkey.net/oauth/token -d \
"client_secret=YOUR_CLIENT_SECRET \
&code=AUTH_CODE \
&redirect_uri=YOUR_REDIRECT_URI \
&client_id=YOUR_CLIENT_ID \
&grant_type=authorization_code"