You definitely need to use PUT, not POST, when editing rosters.
http://developer.yahoo.com/fantasysports/guide/roster-resource.html#roster-resource-PUT
Oh, geez, you know, I didn't even realize that the basic PHP OAuth library doesn't seem to support write operations. :| Here's a PHP example constructing a POST and using CURL -- swap out the $method for PUT and you should be pretty well set. I'll work on updating the documentation to show something like this, too.
This all assumes that you already have sent the user through the authorization flow already, which is detailed in:
http://developer.yahoo.com/fantasysports/guide/GettingStarted.html#GettingStarted-sample
So we'll step back in as of where we try to get an access token after the user has provided us with the verifier at the end of their browser auth flow.
------------------------------------------------------------------
$o = new OAuth( $consumer_key, $consumer_secret,
OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI );
$o->enableDebug();
try {
$o->setToken( $token, $token_secret );
$response = $o->getAccessToken( 'https://api.login.yahoo.com/oauth/v2/get_token', $session_handle, $verifier );
} catch( OAuthException $e ) {
print $e->getMessage() . "\n";
print $e->lastResponse . "\n";
exit;
}
print_r( $response );
print urlencode( $response['oauth_token'] ) . "\n";
print "Got OAuth token\n";
$realm = 'yahooapis.com';
$url = "URL THAT YOU NEED TO PUT/POST TO";
$oauth_consumer_key = $consumer_key;
$oauth_signature_method = 'HMAC-SHA1';
$oauth_nonce = rand( 0, 100000 );
$oauth_timestamp = time();
$oauth_version = "1.0";
$oauth_token = $response['oauth_token'];
$method = 'POST'; // Or 'PUT' if you need to PUT.
$params = '';
$params .= 'oauth_consumer_key=' . urlencode($oauth_consumer_key);
$params .= '&oauth_nonce=' . urlencode($oauth_nonce);
$params .= '&oauth_signature_method=' . urlencode($oauth_signature_method);
$params .= '&oauth_timestamp=' . urlencode($oauth_timestamp);
$params .= '&oauth_token=' . urlencode( $oauth_token );
$params .= '&oauth_version=' . urlencode($oauth_version);
$base_string = urlencode( $method ) . '&' . urlencode( $url ) . '&' .
urlencode( $params );
print 'Base string: ' . $base_string . "\n";
$secret = urlencode( $consumer_secret ) . '&' . urlencode( $response['oauth_token_secret'] );
$signature = base64_encode( hash_hmac( 'sha1', $base_string, $secret, true ) );
print 'Signature: ' . $signature . "\n";
$test_url = $url . '?' . $params . '&oauth_signature=' . urlencode( $signature );
print 'Test URL: ' . $test_url . "\n";
$postdata = '<fantasy_content><XML CONTENT></fantasy_content>';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-type: application/xml' ) );
if( $method == 'POST' ) {
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
} else if( $method == 'PUT' ) {
$putData = tmpfile();
fwrite( $putData, $postdata );
fseek( $putData, 0 );
curl_setopt( $ch, CURLOPT_PUT, 1 );
curl_setopt( $ch, CURLOPT_INFILE, $putData );
curl_setopt( $ch, CURLOPT_INFILESIZE, strlen( $postdata ) );
}
curl_setopt( $ch, CURLOPT_URL, $test_url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$ycw_result = curl_exec( $ch );
$ret_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
if( $method == 'PUT' ) {
fclose( $putData );
}
curl_close( $ch );
print_r( $ycw_result );
print 'Return code: ' . $ret_code . "\n";
------------------------------------------------------------------