shell_exec escaping quotes in php for Twitter API --> Getting CURL to work with obscure twitter api

Posted by yc10 on Stack Overflow See other posts from Stack Overflow or by yc10
Published on 2010-04-01T17:51:58Z Indexed on 2010/04/01 20:13 UTC
Read the original article Hit count: 711

Filed under:
|
|
|

I'm using shell_exec() to execute a Twitter API Call.

shell_exec('curl -u user:password -d "id=3191321" http://api.twitter.com/1/twitterapi/twitterlist/members.xml');

That works fine when I authenticate correctly and put in a number for the id.

But when I try to put in a variable ($id), it screws up.

$addtolist = shell_exec('curl -u pxlist:Weekend1 -d "id='.$id.'" http://twitter.com/username/twitterlist/members.xml');

I tried flipping the quote types

$addtolist = shell_exec("curl -u pxlist:Weekend1 -d 'id=$id' http://twitter.com/username/twitterlist/members.xml");

I tried using double quotes and escaping them

$addtolist = shell_exec("curl -u pxlist:Weekend1 -d \"id=$id\" http://twitter.com/username/twitterlist/members.xml");

None of them worked.

What am I doing wrong?

EDIT: The purists say I should be using PHP's built in curl methods, not the shell_exec. That's not working either.

$url = 'http://twitter.com/user/list/members.xml';

// Set up and execute the curl process

$curl_handle = curl_init();

curl_setopt($curl_handle, CURLOPT_URL, "$url");

curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_handle, CURLOPT_POST, 1);

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "id=$id");

curl_setopt($curl_handle, CURLOPT_USERPWD, "user:pw");

$buffer = curl_exec($curl_handle);

curl_close($curl_handle);

It returns bool(false), and doesn't properly update the Twitter List in question (the whole point of the exercise)

© Stack Overflow or respective owner

Related posts about php

Related posts about shell