Hi Abraham,
I got the "collections/entries/curate.json" to work successfully using the oAuth tool. I forgot to specify the content type in the curl request "-H "Content-Type: application/json"".
Unfortunately I’m still getting the “Cannot Authenticate you” response error when calling request using the php oAuth library.
I’ve been using the php oAuth library that you authored. Here is a snippet of the curl request method with some comments I put in regarding some tests I conducted. Could you please take a look to see if there is something that I’m missing:
private function request($url, $method, $authorization, array $postfields)
{
/* Curl settings */
$options = array(
//CURLOPT_VERBOSE => true,
CURLOPT_CAINFO => __DIR__ . DIRECTORY_SEPARATOR . 'cacert.pem',
CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout,
CURLOPT_HEADER => true,
// TRAVIS: attempted to explicitly set the content type in the header
// still returning "Cannot Authenticate You" error for the json post
//CURLOPT_HTTPHEADER => array('Content-Type: application/json', $authorization, 'Expect:'),
CURLOPT_HTTPHEADER => array('Accept: application/json', $authorization, 'Expect:'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_TIMEOUT => $this->timeout,
CURLOPT_URL => $url,
CURLOPT_USERAGENT => $this->userAgent,
);
if($this->gzipEncoding) {
$options[CURLOPT_ENCODING] = 'gzip';
}
if (!empty($this->proxy)) {
$options[CURLOPT_PROXY] = $this->proxy['CURLOPT_PROXY'];
$options[CURLOPT_PROXYUSERPWD] = $this->proxy['CURLOPT_PROXYUSERPWD'];
$options[CURLOPT_PROXYPORT] = $this->proxy['CURLOPT_PROXYPORT'];
$options[CURLOPT_PROXYAUTH] = CURLAUTH_BASIC;
$options[CURLOPT_PROXYTYPE] = CURLPROXY_HTTP;
}
switch ($method) {
case 'GET':
break;
case 'POST':
$options[CURLOPT_POST] = true;
// original implementation:
// does not work when passing json as post data, returns "Malformed JSON" error
// $options[CURLOPT_POSTFIELDS] = _Util::buildHttpQuery($postfields);
// TRAVIS: test, setting body to specific JSON string as brute force test,
// still returns "Cannot Authenticate You" error in response
$jsonBody = '{"id": "custom-756607134587117568", "changes": [{ "op": "add", "tweet_id": "390890231215292416"}] }';
$options[CURLOPT_POSTFIELDS] = $jsonBody;
break;
case 'DELETE':
$options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
break;
case 'PUT':
$options[CURLOPT_CUSTOMREQUEST] = 'PUT';
break;
}
if (in_array($method, array('GET', 'PUT', 'DELETE')) && !empty($postfields)) {
$options[CURLOPT_URL] .= '?' . _Util::buildHttpQuery($postfields);
}
$curlHandle = curl_init();
curl_setopt_array($curlHandle, $options);
$response = curl_exec($curlHandle);
// Throw exceptions on cURL errors.
if (curl_errno($curlHandle) > 0) {
throw new TwitterOAuthException(curl_error($curlHandle), curl_errno($curlHandle));
}
$this->response->setHttpCode(curl_getinfo($curlHandle, CURLINFO_HTTP_CODE));
$parts = explode("\r\n\r\n", $response);
$responseBody = array_pop($parts);
$responseHeader = array_pop($parts);
$this->response->setHeaders($this->parseHeaders($responseHeader));
curl_close($curlHandle);
return $responseBody;
}
Thanks,
Travis