Hmm, here is the full code I use to create a friendship:

   $host = "http://twitter.com/friendships/create/"; . $userid . ".json";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "$host");
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$from_username:$pass");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($ch, CURLOPT_POST, 1);


    // Go for it!!!
    $result = curl_exec($ch);

Most notable difference is that there are no POSTFIELDS to be sent in
a friendship create request....

Try that out and see what happens?
-Chad

On Thu, Mar 12, 2009 at 7:30 PM, benr <[email protected]> wrote:
>
> Thanks for the reply. I tried with with a 1 instead of true and still
> no dice.
>
> On Mar 12, 5:25 pm, Chad Etzel <[email protected]> wrote:
>> Try instead:
>> curl_setopt ($ch, CURLOPT_POST, 1);
>>
>> -Chad
>>
> - Show quoted text -
>> On Thu, Mar 12, 2009 at 7:21 PM, benr <[email protected]> wrote:
>>
>> > I'm trying to write a function that will follow a user via the API
>> > using PHP/curl. I believe I have setup correctly using curl to POST to
>> > twitter, but I keep getting the following error: "This method requires
>> > a POST.".  Here is my code:
>>
>> > $url = 'http://twitter.com/friendships/create/'.urlencode
>> > ($id).'.json';
>> > $postargs = 'id='.urlencode($id);
>>
>> > $ch = curl_init($url);
>>
>> > curl_setopt ($ch, CURLOPT_POST, true);
>> > curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
>> > curl_setopt($ch, CURLOPT_USERPWD, $this->username.':'.$this-
>> >>password);
>> > curl_setopt($ch, CURLOPT_VERBOSE, 1);
>> > curl_setopt($ch, CURLOPT_NOBODY, 0);
>> > curl_setopt($ch, CURLOPT_HEADER, 0);
>> > curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
>> > curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
>> > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
>> > curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
>>
>> > $response = curl_exec($ch);
>>
>> > $this->responseInfo=curl_getinfo($ch);
>> > curl_close($ch);
>>
>> > All the values appear to be valid. I'm able to update my status using
>> > the above script (different url of course) and other actions, the only
>> > one I'm having trouble with right now is friendship/create.  Am I
>> > missing a CURL opt?

Reply via email to