$requestTokenUrl = "http://www.tumblr.com/oauth/request_token";
$authorizeUrl = "http://www.tumblr.com/oauth/authorize";
$accessTokenUrl = "http://www.tumblr.com/oauth/access_token";
$oauthCallbackUrl = MY_URL;
$consumerKey = MY_KEY;
$oauthTimestamp = time();
$nonce = md5(mt_rand());
$oauthSignatureMethod = "HMAC-SHA1";
$oauthVersion = "1.0";
$sigBase = "POST&" . rawurlencode($requestTokenUrl) . "&"
. rawurlencode(
"oauth_callback=" . rawurlencode($oauthCallbackUrl)
. "oauth_consumer_key=" . rawurlencode($consumerKey)
. "&oauth_nonce=" . rawurlencode($nonce)
. "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
. "&oauth_timestamp=" . $oauthTimestamp
. "&oauth_version=" . $oauthVersion
);
$sigKey = $consumerSecret . "&";
$oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $requestTokenUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: OAuth oauth_consumer_key="' . $consumerKey . '",
oauth_timestamp="' . $oauthTimestamp . '",
oauth_nonce="' . $nonce . '",
oauth_callback="' . $oauthCallbackUrl . '",
oauth_signature_method="' . $oauthSignatureMethod . '",
oauth_version="' . $oauthVersion . '",
oauth_signature="' . $oauthSig . '"'
));
curl_setopt($ch, CURLOPT_POST, 1);
$output = curl_exec($ch);
问题是,我按照关于oauth和twitter的教程编写了上面的代码。我试图结合一些不那么好的tumblr api文档。现在我得到一个oauth 400错误的请求响应,我不能以某种方式调试。实际上,oauth回应是这样的:
HTTP/1.0 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>
并且curl_getinfo显示了这个:
'url' => string 'http://www.tumblr.com/oauth/request_token' (length=41)
'content_type' => string 'text/html' (length=9)
'http_code' => int 400
'header_size' => int 97
'request_size' => int 545
'filetime' => int -1
'ssl_verify_result' => int 0
'redirect_count' => int 0
'total_time' => float 0.377313
'namelookup_time' => float 0.028666
'connect_time' => float 0.198192
'pretransfer_time' => float 0.198388
'size_upload' => float 0
'size_download' => float 90
'speed_download' => float 238
'speed_upload' => float 0
'download_content_length' => float -1
'upload_content_length' => float -1
'starttransfer_time' => float 0.37721
'redirect_time' => float 0
'redirect_url' => string '' (length=0)
'primary_ip' => string '66.6.43.30' (length=10)
'certinfo' =>
array (size=0)
empty
'primary_port' => int 80
'local_ip' => string '192.168.1.70' (length=12)
'local_port' => int 52189
有没有办法知道出了什么问题?任何帮助,将不胜感激。谢谢。
答案 0 :(得分:0)
确定发现了问题。我有卷曲选项
curl_setopt($ch, CURLOPT_POST, 1);
但我还需要添加:
curl_setopt($ch, CURLOPT_POSTFIELDS, array());