tags:

views:

53

answers:

1

Hi,

I am using the Twitter API for OAuth.

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

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

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:'));

Can you please assist?

Thanks.

A: 

I figured this out a while later.

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

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

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

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

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.

Chuck Ugwuh

related questions