tumblr api。得到OAuth。如何获得v2 / user / info? (Php - curl)

时间:2011-12-14 12:39:06

标签: php api tumblr

我正在开发一个应用程序,我必须连接到所有主要的社交网络(Facebook,Tumblr,Twitter,Y!答案,MSN,Youtube开始,更晚些时候)。 我已经为这些中的每一个下载并使用了一种类,但足够了! 我正在重写一个将(应该)处理所有API的类。 我的OAuth现在正在与所有人合作,但是,在tumblr上,虽然我有api_key,oauth_token,oauth_token_secret,当试图curl()获取用户信息(主要是用户/屏幕名称)时,回复总是401,未经授权。 我可能在卷曲选项中设置了一些错误,但是什么?

    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

0 个答案:

没有答案