2017-07-14 76 views
0

我是REST的新用戶,他的任務是使用V3 API檢索SurveyMonkey調查數據。我正在使用PHP。我的代碼如下:調用SurveyMonkey API V3的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 

我已經驗證了我使用的身份驗證令牌是一個發給我,當我登記我的應用程序(目前完成)。

我錯過了什麼嗎?大部分問題和答案都涉及SurveyMonkey API的V2。我正在使用V3。

感謝您的幫助!

+0

問題看起來與你的令牌或什麼不是,似乎是一個錯誤TLS,請確保您的服務器所支持的加密算法。您可以在這裏查看SurveyMonkey支持的內容:https://www.ssllabs.com/ssltest/analyze.html?d=api.surveymonkey.net&latest。對於*測試*如果您確實需要,您可能會禁用握手驗證。 –

+0

謝謝!我相信你是對的。當它工作時,我會發布解決方案,並獎勵你... – dneimeier

+0

沒有快樂。我正在使用OpenSSL v 0.9.8c和TLS1.0。需要升級嗎? – dneimeier

回答

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... */