无法使用 Tumblr API v2 发出 POST 请求

发布于 2024-12-23 10:53:54 字数 1530 浏览 2 评论 0原文

我想做的事情:通过 PHP 连接到 Tumblr API v2 并能够创建新帖子

问题: API 响应始终类似于 OAuth 凭据无效。无法获取信息

奇怪的是,当我执行 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); 

$resultvar_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 但没有运气

我还检查了所有变量来查看令牌是否正常并且它们似乎工作正常。

任何正确方向的提示都将受到赞赏,因为我已经访问了 Google 的第 30 页,并且我只看到与我有相同问题的人。

What I am trying to do: Connect to the Tumblr API v2 via PHP and be able to create new posts

The problem: The API response is always something similar to Invalid OAuth credentials. Unable to get info

The strange part is that I am able to connect to the API (http://www.tumblr.com/docs/en/api/v2) with no problems when I do a GET request but there must be something I must be doing wrong with my signature when I try to create a POST.

Here is my code:

$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); 

A var_dump of $result echoes the following

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

I am not sure the curl_init must be calling http://www.tumblr.com/api/write but I also tried with api.tumblr.com/v2/blog/{base-hostname}/post with no luck

I also checked all the variables to see if the tokens are OK and they seem to be working fine.

Any hint in the right direction will be appreciated as I have went to page 30 of Google and I just see people with the same issue as myself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽袖吟 2024-12-30 10:53:54

我使用大约一年前编写的这个库取得了成功。

我在卷曲之前检查了结果的转储,它看起来或多或少与你的相同,所以我不确定有什么区别。

I've been having success with this library, which was written around a year ago.

I checked the dump of the result before the curl and it looks more or less the same as yours, so i'm not sure what the difference is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文