Я занимаюсь разработкой приложения, в котором я должен подключиться ко ВСЕМ основным социальным сетям (Facebook, Tumblr, Twitter, Y! Answers, MSN, Youtube для начала, подробнее позже).
Я скачал и использовал один тип класса для каждого из них, но этого достаточно!
Я переписываю класс, который будет (должен) справляться со всеми API.
Мой OAuth теперь работает со всеми из них, но на tumblr, хотя у меня есть api_key, oauth_token, oauth_token_secret, при попытке curl () получить информацию о пользователе (в основном имя пользователя / имя экрана), ответ всегда 401, неавторизован.
Я, вероятно, установил что-то не так в настройках curl, но что?
public function curl_it($method, $url, $params=array())
{
switch ($method)
{
case 'POST':
break;
default:
// GET, DELETE request so convert the parameters to a querystring
if ( ! empty($params))
{
foreach ($this->request_params as $k => $v)
{
// Multipart params haven't been encoded yet.
// Not sure why you would do a multipart GET but anyway, here's the support for it
if ($this->config['multipart'])
$params[] = $this->safe_encode($k) . '=' . $this->safe_encode($v);
else
$params[] = $k . '=' . $v;
}
$qs = implode('&', $params);
$this->url = strlen($qs) > 0 ? $this->url . '?' . $qs : $this->url;
$this->request_params = array();
}
break;
}
// configure curl
$c = curl_init();
curl_setopt_array($c, array(
CURLOPT_USERAGENT => $this->config['user_agent'],
CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'],
CURLOPT_TIMEOUT => $this->config['curl_timeout'],
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'],
CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'],
CURLOPT_PROXY => $this->config['curl_proxy'],
CURLOPT_ENCODING => $this->config['curl_encoding'],
CURLOPT_URL => $url,
CURLOPT_HEADERFUNCTION => array($this, 'curlHeader'),
CURLOPT_HEADER => FALSE,
CURLINFO_HEADER_OUT => true
)
);
if ($this->config['curl_proxyuserpwd'] !== false)
curl_setopt($c, CURLOPT_PROXYUSERPWD, $this->config['curl_proxyuserpwd']);
if ($this->config['is_streaming'])
{
// process the body
$this->response['content-length'] = 0;
curl_setopt($c, CURLOPT_TIMEOUT, 0);
curl_setopt($c, CURLOPT_WRITEFUNCTION, array($clas, 'curlWrite'));
}
switch ($method)
{
case 'GET':
curl_setopt($c, CURLOPT_GET, TRUE);
break;
case 'POST':
curl_setopt($c, CURLOPT_POST, TRUE);
break;
default:
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $method);
}
if ( ! empty($params) )
{
// if not doing multipart we need to implode the parameters
if ( ! $this->config['multipart'] )
{
foreach ($params as $k => $v)
{
$ps[] = "{$k}={$v}";
}
$params = implode('&', $ps);
}
curl_setopt($c, CURLOPT_POSTFIELDS, $params);
}
else
{
// CURL will set length to -1 when there is no data, which breaks Twitter
$this->headers['Content-Type'] = '';
$this->headers['Content-Length'] = '';
}
// CURL defaults to setting this to Expect: 100-Continue which Twitter rejects
$this->headers['Expect'] = '';
if ( ! empty($this->headers))
{
foreach ($this->headers as $k => $v)
{
$headers[] = trim($k . ': ' . $v);
}
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
}
if ((isset($this->config['prevent_request'])) && ($this->config['prevent_request'] == false))
return;
// do it!
$response = curl_exec($c);
$code = curl_getinfo($c, CURLINFO_HTTP_CODE);
$info = curl_getinfo($c);
curl_close($c);
// store the response
$this->response['code'] = $code;
$this->response['response'] = $response;
$this->response['info'] = $info;
return $code;
}
Кто-нибудь может помочь?
(Бесполезно идти в дискуссионную группу Tumblr: там никого нет ...)
JR