The code below simply gives me "Failed to validate oauth signature and
token" : really battling to spot the problem here.

// Set url
        $url = "http://api.twitter.com/oauth/request_token";;

        // Params to pass to twitter and create signature
        $params['oauth_callback'] = "http://localhost/twitter/tweet/";;
        $params['oauth_consumer_key'] = $this->consumerKey;
        $params['oauth_nonce'] = SHA1(time());
        $params['oauth_timestamp'] = time();
        $params['oauth_signature_method'] = $this->signatureMethod;
        $params['oauth_version'] = $this->version;
        ksort($params);

        // Signing
            // Concatenating
            $concatenatedParams = '';
            foreach($params as $k => $v)
            {
              $k = urlencode($k);
              $v = urlencode($v);
              $concatenatedParams .= "{$k}={$v}&";
            }
            $concatenatedParams = urlencode(substr($concatenatedParams,
0,-1));

            $signatureBaseString = "POST&".urlencode($url)."&".
$concatenatedParams;
            $params['oauth_signature'] =
base64_encode( hash_hmac('sha1', $signatureBaseString, $this-
>secret."&", true) );


        // Do cURL
        $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
            $exec = curl_exec ($ch);
            $info = curl_getinfo($ch);
        curl_close ($ch);

        print $exec;

Reply via email to