Here is an update on the code... Thanks dalecosp I had that pointed out by someone else as well.
I've worked on converting my code from a GET method to one that POSTs.
But, I'm receiving an error... which in one sense is good, because it shows that stuff is starting to work, but in the other I'm not sure how to fix it.
My code:
// Upload images to flickr
public function uploadPhotos( $photo, $title = null, $tags = null ) {
// Function specific variables
$flickr_upload = "http://up.flickr.com/services/upload/";
$access_token = "my_access_token";
$access_token_secret = "my_access_token_secret";
// Authorization method
$url = "format=" . $this->format;
$url .= "&nojsoncallback=1";
$url .= "&oauth_consumer_key=" . $this->flickr_key;
$url .= "&oauth_nonce=" . $this->nonce;
$url .= "&oauth_signature_method=" . $this->sig_method;
$url .= "&oauth_timestamp=" . $this->timestamp;
$url .= "&oauth_token=" . $access_token;
$url .= "&oauth_version=1.0";
$baseurl = "GET&" . urlencode( $flickr_upload ) . "&" . urlencode( $url );
$hashkey = $this->flickr_secret . "&" . $access_token_secret;
$oauth_signature = base64_encode( hash_hmac( 'sha1', $baseurl, $hashkey, true ));
$url_parameters = array(
'format' =>$this->format,
'nojsoncallback' =>'1',
'oauth_consumer_key' =>$this->flickr_key,
'oauth_nonce' =>$this->nonce,
'oauth_signature_method'=>$this->sig_method,
'oauth_timestamp' =>$this->timestamp,
'oauth_token' =>$access_token,
'oauth_version' =>'1.0',
'oauth_signature' =>$oauth_signature
);
//* Now that we have encoded the parameters for our ouath_signature
//* and have reformated them for the url we need to send... we must
//* re-urlencode them too.
$parameters_string = "";
foreach ( $url_parameters as $key=>$value )
$parameters_string .= "$key=" . urlencode( $value ) . "&";
$parameters_string = rtrim( $parameters_string, '&' );
$url = $flickr_upload . "&" . $parameters_string;
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $flickr_upload );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $parameters_string );
$result = curl_exec( $ch );
curl_close( $ch );
$result = file_get_contents( $result );
print_r( $result );
if (!curl_exec( $ch )) {
// if curl_exec() returned false and thus failed
echo 'An error has occurred.';
}
} // end Upload images
Here is the code that it's outputting:
oauth_problem=signature_invalid&debug_sbs=POST&http%3A%2F%2Fup.flickr.com%2Fservices%2Fupload%2F&format%3Djson%26nojsoncallback%3D1%26oauth_consumer_key%3De5602ede44c8e5fa5e91083df7a091dd%26oauth_nonce%3D6cce3312334fee16eb4050fe6c8ee3e3%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1387257374%26oauth_token%3D72157636982291475-7f2fe214249093ca%26oauth_version%3D1.0 An error has occurred.