phpapicurlposterous

Posterous api php curl


Anyone see anything wrong with this, it is not working and its returning null.

$request = array(
  "api_token" => $token,
  "name" => null,
  "byline" => "via api",
  "owner_id" => null,
  "id" => $id,
  "raw_theme" => $t,
  "friendly_name" => "Test"
);


$session = curl_init($url);
curl_setopt($session, CURLOPT_USERPWD, $user . ":" . $password);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $request);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
var_dump($response);

Solution

  • I'm not sure but if I try to send a create new theme request from https://posterous.com/api then the post parameters are named like:

    theme[byline]
    theme[designer_url]
    theme[friendly_name]
    theme[raw_theme]
    theme[thumb]
    

    So, perhaps you should try changing your code into something like:

    $request = array(
      "api_token" => $token,
      "name" => null,
      "theme[byline]" => "via api",
      "owner_id" => null,
      "id" => $id,
      "theme[raw_theme]" => $t,
      "theme[friendly_name]" => "Test"
    );
    

    Also, I don't see any owner_id, name or id parameters in their example.