PHP中的握手错误调用SurveyMonkey API V3

时间:2017-07-14 18:56:04

标签: php api handshake surveymonkey

我是REST的新手,他的任务是使用V3 API检索SurveyMonkey调查数据。我正在使用PHP。我的代码如下:

$fields = array(
'title'=>'New Admission Survey',
'object_ids' => array($surveyID));

$fieldsString = json_encode($fields);

$curl = curl_init();
$requestHeaders = array(
"Authorization" => 'bearer abc123',
"Content-Type" => 'application/json',
'Content-Length: ' . strlen($fieldsString));

$baseUrl = 'https://api.surveymonkey.net/v3';
$endpoint = '/surveys/';

curl_setopt($curl, CURLOPT_URL, $baseUrl . $endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $requestHeaders);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, $fieldsString);
$curl_response = curl_exec($curl);

if($curl_response == false){
echo('Well, crap');
$info = curl_getinfo($curl);
echo('<pre>');print_r($info);echo('</pre>');
echo('<pre>');print_r(curl_error($curl));echo('</pre>');}
else {
echo('Test: ' . $curl_response);}

curl_close($curl);

我收到以下错误:

error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

我已经验证了我正在使用的Auth Token是我在注册我的应用程序时发给我的那个(今天完成)。

我错过了什么吗?大多数问题和答案都涉及SurveyMonkey API的V2。我正在使用V3。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我不确定这是否有助于您遇到的具体错误,但您是否尝试过使用此API包装器? https://github.com/ghassani/surveymonkey-v3-api-php

这个API包装器大大简化了我的任务:

<?php

// Init the client.
$client = Spliced\SurveyMonkey\Client(MY_CLIENT_ID, MY_ACCESS_TOKEN);

// Get a specific survey.
$survey = $client->getSurvey(MY_SURVEY_ID);

// Get all responses for this survey.
/** @var Spliced\SurveyMonkey\Response $responses */
$responses = $client->getSurveyResponses(MY_SURVEY_ID);

// Get a specific response.
/** @var Spliced\SurveyMonkey\Response $response */
$response = $client->getSurveyResponse(MY_SURVEY_ID, RESPONSE_ID, TRUE);

/* etc... */