This is extremely frustrating because that is exactly what I've been
doing all along. In order to call to the API I created a method for
the OAuth Object and a standalone function and call them in sequential
order:
function CreateRequestUrl($url,$params=null,$method="GET") {
if ($params=="GET" || $params=="POST") {
$method = $params;
$params = null;
}
$request = OAuthRequest::from_consumer_and_token($this->consumer,
$this->access_token,$method,$url,$params);
$request->sign_request($this->sig_method,$this->consumer,$this-
>access_token);
return $request->to_url();
}
The above creates a new request every time using the method specified
and uses the CONSUMER and ACCESS_TOKEN which is stored in my OAuth
Object. This will output the URL with all the OAuth info in it. So
for the commands I do the following line:
$url = $sp->CreateRequestUrl("
http://springpadit.com/api/users/me/
commands","POST");
I then follow this up by making the call to the server using the next
function:
function FetchUrl($url,$command=null) {
$ch = curl_init($url);
if ($command) {
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$command);
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
So call looks like this:
$command = stripslashes(json_encode(array(array('create','Workbook',
$uuid))));
$res = FetchUrl($url,$command);
I generate the UUID by taking the shard + "3" + correctly formatted
random UUID generated based on timestamp.
It doesn't make any sense why I can't authorize as soon as I add the
commands to the body. I've looked to see if its a bug with cURL but
people can post JSON commands to the body with zero problems with very
similar code. Maybe someone who uses PHP can brainstorm with me
because this is the only thing I'm missing for a fully working PHP
API.
Also, Pete, your Python code is no longer available on the repository.