0

Downloading Attachments in Perl

I can't seem to figure out how to download attachments, here's the current data dump where I get stuck

QUOTE
$VAR1 = bless( { '_content' => '500 read timeout ', '_rc' => 500, '_headers' => bless( { 'client-warning' => 'Internal response', 'client-date' => 'Thu, 21 Apr 2011 19:01:51 GMT', 'content-type' => 'text/plain' }, 'HTTP::Headers' ), '_msg' => 'read timeout', '_request' => bless( { '_content' => '{"params":[{"inline":1,"mid":"1_5508_AElXimIAAXKoTa37BgoNP1fRjUM","pid":2,"fid":"Inbox","clean":0}],"method":"DownloadAttachment"}', '_uri' => bless( do{\(my $o = 'http://mail.yahooapis.com/ya/download?oauth_consumer_key=dj0yJmk9SUJaMzRUeGJmaXBFJmQ9WVdrOVRGcFRjblJMTldrbWNHbzlNemt4T
0RnMU1qWXkmcz1jb25zdW1lcnNlY3JldCZ4PWY0&oauth_nonce=2603621406&oauth_signature=0ijeAMoDAX5yh2heXZcDPUNXj38%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1303412496&oauth_token=A%3DD4UWjlDDkTEYxMelwqRmmIEXwjSpKSNoauiAmt6hqLqHxy6YRENGa1rOirmLKq2QDpPoTqFiyB8XCN
51DCyA5K.TfOVHwSxVvyv80W6gYmtcb6vUnbY9tSqhj71jmGRZN4oFCTTCbjzVwLZoBdWwKHxga8JG3yP
FrutTVuEFaujE0amfeCF1CgeM.BVKdMdyMCjyXcevVUGKjCbeCp9HG2ypeA9MWaiqG9WsHdUwe2RYhKzE
G6DoG_rf9jNPEk4Qpm7LpVQl_uL3mwEvI29i1hGcS.79uBVjhp0NLnSQX6ldcGBGKUGenUyOzVFnNSSaF
yTy2.KwxINjFrHrdqY3ZHsNiLPA1wuaP95f.4FNAgkM3LNENdfvbTTJ.Bh61dQsfRt6jfrXtwhSnMQaiY
SlhmJ10f17.wtnFDSvqxG0p2Vo2W_uHYH4Ge8yZ2Hrvm4_4C8CfwsGYbnaCZoXfzKdeu5GlmEKJne1HE4
enP7IyYp_e1CwA.c8ufmedewLWqyD_FZO8Oeu1sdrEAyFCUlSM8X9fy5eVoTk78SuLz0AKQed7afyJ01x
6iQlB2IKwVSeX0R9tXb.8OdLyvMdbl4PKORT1TWlc5sNn1lpu7B1dc3i6F4Sq.mgjED8UVOliw.uICWQf
GMWVoRJmMfgpPBcH58WSsN36wPaxK5ODQAj._m01N.rSB0xLCErBIjuCMpZVEaxEu0yz7O8qejJyH_cIY
qMR2lLN1CQWZ1oSXqMO9AmzudhwZkjAgHOp3uC4M1G7hOo3BiD8A--&oauth_version=1.0')}, 'URI::http' ), '_headers' => bless( { 'user-agent' => 'libwww-perl/5.825', 'content-type' => 'application/json; charset=UTF-8' }, 'HTTP::Headers' ), '_method' => 'GET' }, 'HTTP::Request' ) }, 'HTTP::Response' );


Can anyone help at all?

by
5 Replies
  • This is easier to read --

    CODE
    $VAR1 = bless( {
    '_content' => '500 read timeout
    ',
    '_rc' => 500,
    '_headers' => bless( {
    'client-warning' => 'Internal response',
    'client-date' => 'Thu, 21 Apr 2011 19:01:51 GMT',
    'content-type' => 'text/plain'
    }, 'HTTP::Headers' ),
    '_msg' => 'read timeout',
    '_request' => bless( {
    '_content' => '{"params":[{"inline":1,"mid":"1_5508_AElXimIAAXKoTa37BgoNP1fRjUM","pid":2,"fid":"Inbox","clean":0}],"method":"DownloadAttachment"}',
    '_uri' => bless( do{\(my $o = 'http://mail.yahooapis.com/ya/download?oauth_consumer_key=dj0yJmk9SUJaMzRUeGJmaXBFJmQ9WVdrOVRGcFRjblJMTldrbWNHbzlNemt4T
    0RnMU1qWXkmcz1jb25zdW1lcnNlY3JldCZ4PWY0&oauth_nonce=2603621406&oauth_signature=0ijeAMoDAX5yh2heXZcDPUNXj38%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1303412496&oauth_token=A%3DD4UWjlDDkTEYxMelwqRmmIEXwjSpKSNoauiAmt6hqLqHxy6YRENGa1rOirmLKq2QDpPoTqFiyB8XCN
    51DCyA5K.TfOVHwSxVvyv80W6gYmtcb6vUnbY9tSqhj71jmGRZN4oFCTTCbjzVwLZoBdWwKHxga8JG3yP
    FrutTVuEFaujE0amfeCF1CgeM.BVKdMdyMCjyXcevVUGKjCbeCp9HG2ypeA9MWaiqG9WsHdUwe2RYhKzE
    G6DoG_rf9jNPEk4Qpm7LpVQl_uL3mwEvI29i1hGcS.79uBVjhp0NLnSQX6ldcGBGKUGenUyOzVFnNSSaF
    yTy2.KwxINjFrHrdqY3ZHsNiLPA1wuaP95f.4FNAgkM3LNENdfvbTTJ.Bh61dQsfRt6jfrXtwhSnMQaiY
    SlhmJ10f17.wtnFDSvqxG0p2Vo2W_uHYH4Ge8yZ2Hrvm4_4C8CfwsGYbnaCZoXfzKdeu5GlmEKJne1HE4
    enP7IyYp_e1CwA.c8ufmedewLWqyD_FZO8Oeu1sdrEAyFCUlSM8X9fy5eVoTk78SuLz0AKQed7afyJ01x
    6iQlB2IKwVSeX0R9tXb.8OdLyvMdbl4PKORT1TWlc5sNn1lpu7B1dc3i6F4Sq.mgjED8UVOliw.uICWQf
    GMWVoRJmMfgpPBcH58WSsN36wPaxK5ODQAj._m01N.rSB0xLCErBIjuCMpZVEaxEu0yz7O8qejJyH_cIY
    qMR2lLN1CQWZ1oSXqMO9AmzudhwZkjAgHOp3uC4M1G7hOo3BiD8A--&oauth_version=1.0')}, 'URI::http' ),
    '_headers' => bless( {
    'user-agent' => 'libwww-perl/5.825',
    'content-type' => 'application/json; charset=UTF-8'
    }, 'HTTP::Headers' ),
    '_method' => 'GET'
    }, 'HTTP::Request' )
    }, 'HTTP::Response' );
    0
  • Maybe the endpoint I'm using isn't right??

    The doc says I should be using
    http://mail.yahooapis.com/ya/download
    Although it doesn't say that endpoint wants JSON and that's what I'm feeding it

    Should I be using
    http://mail.yahooapis.com/ws/mail/v1.1/jsonrpc
    And giving it the method DownloadAttachment?


    Please help
    0
  • AHHH!!! I figured it out, here's the Perl code --

    CODE
    			 my $url = "http://mail.yahooapis.com/ya/download";
    $url = $url."?mid=$mid&fid=Inbox&pid=2&tnef=&clean=0";

    $request = Net::OAuth->request("protected resource")->new(
    consumer_key => $consumer_key,
    consumer_secret => $consumer_secret,
    request_url => $url,
    request_method => 'GET',
    signature_method => 'HMAC-SHA1',
    timestamp => $timestamp,
    nonce => $nonce,
    token => $oauth_token,
    token_secret => $oauth_token_secret,
    signature => $oauth_signature,
    clean => 0
    );
    $request->sign;

    my $browser = LWP::UserAgent->new;
    $browser->timeout(180);
    $response = $browser->get($request->to_url);

    open (ATTACHEDFILE, '>test.pdf');
    print ATTACHEDFILE $response->content;
    close (ATTACHEDFILE);
    0
  • Just an FYI for anyone else who might get stuck, you don't feed JSON to the download attachment endpoint, you just build a big URL with the info it in as I did above
    0
  • Hi Jim,
    I have the same problem, and I build the long URL as you wrote here, but still - 404..
    did u make any other changes?
    does it still work?

    Thanks,
    Asi.

    QUOTE(Jim Frey @ 21 Apr 2011 1:07 PM)
    AHHH!!! I figured it out, here's the Perl code --

    CODE
    <!--ec1-->			 my $url = &quot;http://mail.yahooapis.com/ya/download&quot;;<br>				$url = $url.&quot;?mid=$mid&fid=Inbox&pid=2&tnef=&clean=0&quot;;<br><br> 			 $request = Net::OAuth-&gt;request(&quot;protected resource&quot;)-&gt;new(<br>			      consumer_key =&gt; $consumer_key,<br>			      consumer_secret =&gt; $consumer_secret,<br>			      request_url =&gt; $url,<br>			      request_method =&gt; &#39;GET&#39;,<br> 			      signature_method =&gt; &#39;HMAC-SHA1&#39;,<br> 			      timestamp =&gt; $timestamp,<br> 			      nonce =&gt; $nonce,<br> 			      token =&gt; $oauth_token,<br> 			      token_secret =&gt; $oauth_token_secret,<br> 			      signature =&gt; $oauth_signature, <br> 			      clean =&gt; 0<br> 			    );<br>				$request-&gt;sign;<br><br>				my $browser = LWP::UserAgent-&gt;new;<br>				$browser-&gt;timeout(180);<br>				$response = $browser-&gt;get($request-&gt;to_url);<br><br>				open (ATTACHEDFILE, &#39;&gt;test.pdf&#39;);<br>				print ATTACHEDFILE $response-&gt;content;<br>				close (ATTACHEDFILE);<!--c2--></code>
    0

Recent Posts

in Yahoo! Mail Web Services API