Passing array as parameter to curl post

I had a previous post on this topic but this is a different way of doing it so …

I’m trying to get a ‘stream’ of statuses back from twitters streamed tweets resources using a filter http://dev.twitter.com/doc/post/statuses/filter

These are the methods from the streaming API http://dev.twitter.com/pages/streaming_api_methods from those methods I essentially created this: (keep in mind that this is my first time using curl or the twitter api so I’m possibly way off) Im fairly certain my request is at least working because twitter is returning "No filter parameters found. Expect at least one parameter: follow track locations annotations " keeping in mind I’ve tried many different variations of creating the usernames array

    $url="http://stream.twitter.com/1/statuses/filter.json";
    
    $users = array("follow" => "'twitterusernameOne','twitterusernameTwo'");
    $serializedUsers = urlencode(serialize($users));
    $postFields = urlencode($users);
 
    // Create the connection handle
    $curl_conn = curl_init();
    
    // Set cURL options
    curl_setopt($curl_conn, CURLOPT_URL, $url); //URL to connect to
    curl_setopt($curl_conn, CURLOPT_POST, 1); //Use POST method
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
    
    curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Use basic authentication
    curl_setopt($curl_conn, CURLOPT_USERPWD, 'myusername:mypassword'); //Set u/p
    curl_setopt($curl_conn, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl_conn, CURLOPT_RETURNTRANSFER, 1); //Return the result as string

    $output = curl_exec($curl_conn);
    curl_close($curl_conn);
    
    print_r($output);
   

You create the variables $users, $serializedUsers and $postFields but do not send any of those with your cURL request. First thing is to decide what you’re going to name the variables, then use those names consistently in the code.

I believe your POST body should be “follow=1,2” where 1 and 2 are the IDs of the two users you want to use as a filter. You can’t pass a PHP array of usernames.

The sarcasm while appreciated does not really help — your comment was addressed before you wrote it “keeping in mind I’ve tried many different variations of creating the usernames array

What I meant by that is – the code is a bit in disarray and I’d like someone to help put the pieces together not waste my time with jokes.

There was no sarcasm there, only instructions for fixing your code. You have created different versions of that array, but you did not send any of them with your request because you used different variable names ($postFields, $post_fields) in different parts of your code. The first thing you need to do is correct that inconsistency, the second thing you need to do is get the content of those variables correct.

not to be ungrateful though I do appreciate this “I believe your POST body should be “follow=1,2” where 1 and 2 are the IDs of the two users you want to use as a filter. You can’t pass a PHP array of usernames.”

:slight_smile: