Twitter API 问题:使用 GET 的 OAuth 请求令牌有效,POST 失败 [英] Twitter API Issue: OAuth Request Token using GET works, POST fails

查看:57
本文介绍了Twitter API 问题:使用 GET 的 OAuth 请求令牌有效,POST 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Twitter API 用于 OAuth.

I am using the Twitter API for OAuth.

我已经让请求令牌操作正常工作,使用 GET 没有任何问题.

I have gotten the Request Token operation to work without any issues using GET.

但是,当我使用 POST 执行完全相同的操作时,它给了我错误无法验证 oauth 签名".

However, when I do the exact same thing using POST, it gives me the error 'Failed to validate oauth signature'.

以下是我使用的各种 curl 选项:

Here are the various curl options I am using:

curl_setopt($ch, CURLOPT_URL, ''.$url_post_str.'');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars_arr);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

你能帮忙吗?

谢谢.

推荐答案

我后来想通了.

事实证明,因为我在帖子字段中使用了一个数组,即

It turns out that because I was using an array for the post fields i.e.

curl_setopt($ch, CURLOPT_POSTFIELDS, **$post_vars_arr**);

表单内容类型是 multipart/form-data,Twitter OAuth API 不支持.

the form content type was multipart/form-data, which is not supported by the Twitter OAuth API.

所以我不得不将这个数组内爆为一个查询字符串并将其传递给相同的 curl_setopt 即

So I had to implode this array to a query-string and pass it to the same curl_setopt i.e.

curl_setopt($ch, CURLOPT_POSTFIELDS, **$post_vars_str**);

据我所知,当您使用查询字符串而不是数组时,表单内容类型将是 application/x-www-form-urlencoded(Twitter API 支持)而不是 multipart/form-data.

From what I understand, when you use a query-string instead of an array, the form content type will be application/x-www-form-urlencoded(which is supported by Twitter API) and not multipart/form-data.

这就是我让它工作的方式.我希望它可以帮助其他人.

And that's how I got it work. I hope it helps someone else.

这篇关于Twitter API 问题:使用 GET 的 OAuth 请求令牌有效,POST 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆