Hi,
I am giving an outline of a standard download request. I hope this helps.
$endPointDownload = 'http://mail.yahooapis.com/ya/download';
//Create your Download request query string.
$queryString = $endPointDownload . "?";
$queryString .= "mid=".urlencode($midRequest);
$queryString .= "&fid=Inbox";
$queryString .= "&pid=2";
$queryString .= "&clean=0";
$queryString .= "&output=xml";
//if needed.
$downloadheader = new stdclass(); // hold this for loading content-disposition, content-length and error if any.
//OAuth header for download request
$request_args = array(
'oauth_nonce'=>mt_rand(),
'oauth_timestamp'=>time(),
'oauth_version'=>'1.0',
'oauth_signature_method'=>'HMAC-SHA1',
'oauth_consumer_key'=>$OAuthConsumerKey,
'oauth_token'=>$oauth_token,
'mid'=>$midRequest, // Make sure its the correct mid.
'fid'=>'Inbox', // Folder id
'pid'=>'2', // part id.
'clean'=>'0',
'output'=>'xml'
);
//Note its a GET
$request = new OAuthRequest('GET', "$endPointDownload", $request_args);
$request->sign_request($signature, new OAuthConsumer('', $OAuthConsumerSecret), new OAuthToken('', $oauth_token_secret));
$oauthHeaderForDownloadJson = $request->to_header();
//Do curl_exec
$ch = curl_init($queryString);
curl_setopt($ch,CURLOPT_HTTPHEADER,array($oauthHeaderForDownloadJson));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "readDownloadHeader");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$rawresponse = curl_exec($ch);
var_dump($rawresponse);
//Get downloaded data
$response = new stdclass();
$response->body = $rawresponse;
$response->code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response->contenttype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$response->contentlength = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
response->lasteffectiveurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$response->contentdisposition = isset($downloadheader->contentdisposition)? $downloadheader->contentdisposition : "";
$response->headercontentlength = isset($downloadheader->contentlength)? $downloadheader->contentlength : 0;
$response->errormessage = isset($downloadheader->errormessage)? $downloadheader->errormessage : "";
var_dump($response);
function readHeaderInformation($ch, $header) {
//read from header if needed - info like conten-tdisposition, content-length and error-message
//$downloadheader->contentdisposition, $downloadheader->contentlength, $downloadheader->errormessage
}
--R
Does anybody have working example PHP code for a download attachment?