我想做的是:通过PHP连接到Tumblr API v2,并能够创建新的帖子
问题: API响应总是类似于Invalid OAuth credentials. Unable to get info
奇怪的部分是,当我做一个GET请求时,我能够连接到API (http://www.tumblr.com/docs/en/api/v2)没有问题,但是当我尝试创建一个POST时,我的签名一定是错的。
下面是我的代码:$params = array("type" => "quote", "quote"=>"test" );
$consumer = new OAuthConsumer($consumer_key, $consumer_secret, null);
$token = new OAuthConsumer($access_token['oauth_token'], $consumer_secret);
$req_req = OAuthRequest::from_consumer_and_token($consumer, $token,
"POST", 'http://api.tumblr.com/v2/blog/MY_URL/post', $params);
$req_req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(),
$consumer, $token, null);
$result = $req_req->to_postdata();
$ch = curl_init('http://www.tumblr.com/api/write');
curl_setopt($ch, CURLOPT_URL, 'http://www.tumblr.com/api/write');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $result);
$result
的var_dump
响应如下
oauth_consumer_key=xxxxxxxx&oauth_nonce=xxxxxxx&oauth_signature=xxxxxx
&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1325033502&oauth_token=xxxxxx
&oauth_version=1.0"e=test&type=quote
我不确定curl_init
必须调用http://www.tumblr.com/api/write
,但我也尝试了api.tumblr.com/v2/blog/{base-hostname}/post
,没有运气
我还检查了所有的变量,看看是否令牌是OK的,他们似乎工作得很好。
任何正确方向的提示都会很感激,因为我已经去了谷歌第30页,我只看到和我有同样问题的人。
我一直在使用这个库,它是大约一年前编写的。
我检查了curl之前的转储结果,它看起来或多或少与您的相同,所以我不确定差异是什么