0

Downloading an attachment issues

Hello, I am working on a project for a client and have a PHP script that downloads an attachment from Yahoo! Mail. I have the OAuth working correctly (resolved those issues on Sunday) and get a mid via ListMessages. The mid that is used has 2 attachment (the first is a PDF) and has a pid of 2. When I use a URL with the OAuth and no references to the message, folder, or part, I get a valid header response, see below:

http://mail.yahooapis.com/ya/download/?oau...th_signature=...

Array
(
[0] => HTTP/1.0 500 unable_to_get_message_info_or_part
[Date] => Thu, 23 Dec 2010 15:09:56 GMT
[P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
[Vary] => Accept-Encoding
[Content-Type] => text/html; charset=utf-8
[Cache-Control] => private
[Age] => 0
[Server] => YTS/1.17.23
)

However, once I add a valid mid, folder, and type, then I get a 404 (Not Found) error:

http://mail.yahooapis.com/ya/download/?oau...=0&inline=0

Array
(
[0] => HTTP/1.0 404 Not Found
[Date] => Thu, 23 Dec 2010 15:12:45 GMT
[P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
[Vary] => Accept-Encoding
[Content-Type] => text/html; charset=iso-8859-1
[Age] => 0
[Server] => YTS/1.17.23
)


______________________

http://mail.yahooapis.com/ya/download/?oau...k&fid=Inbox

Array
(
[0] => HTTP/1.0 404 Not Found
[Date] => Thu, 23 Dec 2010 15:19:10 GMT
[P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
[Vary] => Accept-Encoding
[Content-Type] => text/html; charset=iso-8859-1
[Age] => 0
[Server] => YTS/1.17.23
)

________________________

http://mail.yahooapis.com/ya/download/?oau...Inbox&pid=2

Array
(
[0] => HTTP/1.0 404 Not Found
[Date] => Thu, 23 Dec 2010 15:20:39 GMT
[P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
[Vary] => Accept-Encoding
[Content-Type] => text/html; charset=iso-8859-1
[Age] => 0
[Server] => YTS/1.17.23
)

If someone could point me in the right direction as to what I am doing wrong it would be appreciated.


Thank you.

by
10 Replies
  • Hi,

    Can you please add the entire request and response headers of a valid oauth session? These are the list of error codes. The first url pasted below says " 500 unable_to_get_message_info_or_part" which I believe has something to do with the download params and its values. The rest of the 404s is not related to download but with auth stuff.

    The req should be a GET and have &mid=1_6954_AMvJjkQAAJJjTQgZpgDJg1E/Jsk&fid=Inbox&pid=2&tnef=0&clean=0&inline=0.


    --R

    QUOTE (Obiora @ Dec 23 2010, 07:32 AM) <{POST_SNAPBACK}>
    Hello, I am working on a project for a client and have a PHP script that downloads an attachment from Yahoo! Mail. I have the OAuth working correctly (resolved those issues on Sunday) and get a mid via ListMessages. The mid that is used has 2 attachment (the first is a PDF) and has a pid of 2. When I use a URL with the OAuth and no references to the message, folder, or part, I get a valid header response, see below:

    http://mail.yahooapis.com/ya/download/?oau...th_signature=...

    Array
    (
    [0] => HTTP/1.0 500 unable_to_get_message_info_or_part
    [Date] => Thu, 23 Dec 2010 15:09:56 GMT
    [P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    [Vary] => Accept-Encoding
    [Content-Type] => text/html; charset=utf-8
    [Cache-Control] => private
    [Age] => 0
    [Server] => YTS/1.17.23
    )

    However, once I add a valid mid, folder, and type, then I get a 404 (Not Found) error:

    http://mail.yahooapis.com/ya/download/?oau...=0&inline=0

    Array
    (
    [0] => HTTP/1.0 404 Not Found
    [Date] => Thu, 23 Dec 2010 15:12:45 GMT
    [P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    [Vary] => Accept-Encoding
    [Content-Type] => text/html; charset=iso-8859-1
    [Age] => 0
    [Server] => YTS/1.17.23
    )


    ______________________

    http://mail.yahooapis.com/ya/download/?oau...k&fid=Inbox

    Array
    (
    [0] => HTTP/1.0 404 Not Found
    [Date] => Thu, 23 Dec 2010 15:19:10 GMT
    [P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    [Vary] => Accept-Encoding
    [Content-Type] => text/html; charset=iso-8859-1
    [Age] => 0
    [Server] => YTS/1.17.23
    )

    ________________________

    http://mail.yahooapis.com/ya/download/?oau...Inbox&pid=2

    Array
    (
    [0] => HTTP/1.0 404 Not Found
    [Date] => Thu, 23 Dec 2010 15:20:39 GMT
    [P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    [Vary] => Accept-Encoding
    [Content-Type] => text/html; charset=iso-8859-1
    [Age] => 0
    [Server] => YTS/1.17.23
    )

    If someone could point me in the right direction as to what I am doing wrong it would be appreciated.


    Thank you.
    0
  • QUOTE (Ram @ Dec 23 2010, 10:33 AM) <{POST_SNAPBACK}>
    Hi,

    Can you please add the entire request and response headers of a valid oauth session? These are the list of error codes. The first url pasted below says " 500 unable_to_get_message_info_or_part" which I believe has something to do with the download params and its values. The rest of the 404s is not related to download but with auth stuff.

    The req should be a GET and have &mid=1_6954_AMvJjkQAAJJjTQgZpgDJg1E/Jsk&fid=Inbox&pid=2&tnef=0&clean=0&inline=0.


    --R


    Yes, for OAuth the request is below and the header does specify signature invalid. It was working earlier, so what would cause it now to do not do so?

    http://mail.yahooapis.com/ws/mail/v1.1/jso...osRmfAqKccqs%3D

    Array
    (
    [0] => HTTP/1.0 401 Authorization Required
    [1] => Date: Thu, 23 Dec 2010 20:34:20 GMT
    [2] => WWW-Authenticate: OAuth oauth_problem="signature_invalid", realm="yahooapis.com"
    [3] => Content-Type: application/xml
    [4] => Age: 0
    [5] => Server: YTS/1.17.23
    )

    And for downloading the attachment, they are below:


    Array
    (
    [0] => GET
    [1] => Authorization: OAuth realm="yahooapis.com", oauth_nonce="690970614", oauth_consumer_key="...", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1293136466", oauth_version="1.0", oauth_token="..."
    )
    Array
    (
    [0] => HTTP/1.0 404 Not Found
    [1] => Date: Thu, 23 Dec 2010 20:34:21 GMT
    [2] => P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    [3] => Vary: Accept-Encoding
    [4] => Content-Type: text/html; charset=iso-8859-1
    [5] => Age: 0
    [6] => Server: YTS/1.17.23
    )

    Thank you.
    0
  • Happy New Year!

    In trying to download an attachment, I have the prerequisite steps working properly, which include getting the oauth_token, authenticating the user, and getting an access token.

    For downloading the URL, I have tried two different methods to get it work:

    1) I have created an authorization header, which does give me an error message of invalid signature (two different OAUTH libraries have been used), and the error message is vague as to what causes the "invalid_signature" error.

    This is the URL:

    http://mail.yahooapis.com/ws/mail/v1.1/jso...gOro3%2B5CX0%3D

    Full response headers are below:

    Date: Sun, 02 Jan 2011 21:44:17 GMT
    WWW-Authenticate: OAuth oauth_problem="signature_invalid", realm="yahooapis.com"
    Content-Type: application/xml
    Age: 0
    Transfer-Encoding: chunked
    Connection: keep-alive
    Server: YTS/1.17.23

    401 Authorization Required

    2)

    When trying to connect directly to download attachment the URL looks like this:

    http://mail.yahooapis.com/ya/download/?oau...6Vh6GmEg0lYM%3D

    The header response is below:

    Date: Sun, 02 Jan 2011 21:46:04 GMT
    P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    Vary: Accept-Encoding
    Content-Type: text/html; charset=iso-8859-1
    Age: 0
    Transfer-Encoding: chunked
    Connection: keep-alive
    Server: YTS/1.17.23

    404 Not Found

    If someone could please help to steer me in the right direction, this would be appreciated.

    Thank you.


    Obiora
    0
  • Okay, I can't say that Yahoo! has been much help on resolving this issue nor is their documentation adequate to help developers who have issues or problems with downloading or uploading an attachment but I finally have gotten it work successfully. Below is an example of the code in PHP for others that have been struggling to get it work:

    $request = new OAuthRequest('GET', "http://mail.yahooapis.com/ya/download/?mid=$mid&fid=Inbox&pid=2&clean=0&inline=0", array(
    'oauth_consumer_key'=>$OAuthConsumerKey,
    'oauth_nonce'=>mt_rand(),
    'oauth_signature_method'=>'HMAC-SHA1',
    'oauth_timestamp'=>time(),
    'oauth_token'=>$oauth_token,
    'oauth_version'=>'1.0',
    'oauth_callback'=>'oob'));
    $request->sign_request($signature, new OAuthConsumer('', $OAuthConsumerSecret), new OAuthToken('', $oauth_token_secret));
    $oauthURL = $request->to_url();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $oauthURL);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $header = curl_exec($ch);
    curl_close($ch);

    ___________________

    If you get the contents of $header, it will contain the downloaded attachment.

    The OAuth library and above functions come from the phpsample code that can be downloaded after going to this URL: http://developer.yahoo.com/mail/docs/user_...ialTheUser.html

    Hopefully the above can be useful to someone who has not gotten a response from Yahoo!, couldn't find anything online while doing a search, or in the forums.
    0
  • Hi,

    Glad you got it. For some reason your post on Jan 2nd got missed out so my apologies for that. We are making changes in our documentation and adding more code to help developers see the implementation of these APIs. Let us know if you need anything in specific. We will be more than happy to help. Thanks.

    --R


    QUOTE (Obiora @ Feb 5 2011, 11:10 AM) <{POST_SNAPBACK}>
    Okay, I can't say that Yahoo! has been much help on resolving this issue nor is their documentation adequate to help developers who have issues or problems with downloading or uploading an attachment but I finally have gotten it work successfully. Below is an example of the code in PHP for others that have been struggling to get it work:

    $request = new OAuthRequest('GET', "http://mail.yahooapis.com/ya/download/?mid=$mid&fid=Inbox&pid=2&clean=0&inline=0", array(
    'oauth_consumer_key'=>$OAuthConsumerKey,
    'oauth_nonce'=>mt_rand(),
    'oauth_signature_method'=>'HMAC-SHA1',
    'oauth_timestamp'=>time(),
    'oauth_token'=>$oauth_token,
    'oauth_version'=>'1.0',
    'oauth_callback'=>'oob'));
    $request->sign_request($signature, new OAuthConsumer('', $OAuthConsumerSecret), new OAuthToken('', $oauth_token_secret));
    $oauthURL = $request->to_url();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $oauthURL);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $header = curl_exec($ch);
    curl_close($ch);

    ___________________

    If you get the contents of $header, it will contain the downloaded attachment.

    The OAuth library and above functions come from the phpsample code that can be downloaded after going to this URL: http://developer.yahoo.com/mail/docs/user_...ialTheUser.html

    Hopefully the above can be useful to someone who has not gotten a response from Yahoo!, couldn't find anything online while doing a search, or in the forums.
    0
    • Aug 23, 2012
    hello,
    i am working om this issue, and it keeps give me 404-not found, i am using asp.net with OAuthBase.
    could you please provide me with complete success web request in asp.net/c#
    please help :(
    0
  • I cannot help you with with your request as I do not use ASP.Net nor C#, but hopefully someone else can help you.
    0
    • Aug 27, 2012
    thanx for your reply, could you help with my questions:

    1. which parameters should i include in the query string of http://mail.yahooapis.com/ya/download.
    2. should i include headers in the request for authentication fields like: access token, token secret, session handle...etc.
    3. i use OAuthBase for creating signature, right?
    4.is this the correct way to generate signature
    --oauth.GenerateSignature('http://mail.yahooapis.com/ya/download ', consumer_key, consumer_secret, access_token, token_secret, "GET", timeStamp, nonce, '', '');




    thanx for your help again.

    QUOTE(Obiora @ 23 Aug 2012 2:11 PM)
    I cannot help you with with your request as I do not use ASP.Net nor C#, but hopefully someone else can help you.
    0
  • I have not worked on the project for 2 years but I do have the code that I =
    used.=A0 I am including the PHP code below:

    // 1) Get Request Token
    $request =3D new OAuthRequest('GET', "$OAuthEndPoint/get_request_token", ar=
    ray(
    =A0=A0=A0 'oauth_nonce'=3D>mt_rand(),
    =A0=A0=A0 'oauth_timestamp'=3D>time(),
    =A0=A0=A0 'oauth_version'=3D>'1.0',
    =A0=A0=A0 'oauth_signature_method'=3D>'PLAINTEXT', //'HMAC-SHA1'
    =A0=A0=A0 'oauth_consumer_key'=3D>$OAuthConsumerKey,
    =A0=A0=A0 'oauth_callback'=3D>'oob'));
    $url =3D $request->to_url()."&oauth_signature=3D$OAuthConsumerSecret%26";
    //$url =3D $request->to_url()."&oauth_signature=3D".$signature->build_signa=
    ture( $request, new OAuthConsumer('', $OAuthConsumerSecret), NULL);
    $ch =3D curl_init();
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $ch, CURLOPT_URL, $url );
    $resp =3D curl_exec( $ch );
    curl_close($ch);
    parse_str($resp,$tokens);
    $oauth_token =3D $tokens['oauth_token'];
    $oauth_token_secret =3D $tokens['oauth_token_secret'];

    if (!$oauth_token || !$oauth_token_secret) {
    =A0=A0=A0 throw new Exception($resp);=A0=A0=A0=20
    }

    // 2) Get User Auth
    echo " Open this Url in your browser ->> $OAuthEndPoint/request_auth?oauth_=
    token=3D$oauth_token \n";
    echo " This should be provided to end users of your application.End users s=
    hould provide their=20
    'Username' and 'Password' and sign-in which means they authorize your app. =
    On successful login the end users will see a code in the page \n";
    echo " This code is the oauth_token which Yahoo returns to your app \n";
    echo " Enter the code here: ";
    $oauth_verifier =3D trim(fgets(STDIN));

    // 3) Get Access Token
    $request =3D new OAuthRequest('GET', "$OAuthEndPoint/get_token", array(
    =A0=A0=A0 'oauth_nonce'=3D>mt_rand(),
    =A0=A0=A0 'oauth_timestamp'=3D>time(),
    =A0=A0=A0 'oauth_version'=3D>'1.0',
    =A0=A0=A0 'oauth_signature_method'=3D>'PLAINTEXT', //'HMAC-SHA1'
    =A0=A0=A0 'oauth_consumer_key'=3D>$OAuthConsumerKey,
    =A0=A0=A0 'oauth_token'=3D>$oauth_token,
    =A0=A0=A0 'oauth_verifier'=3D>$oauth_verifier));
    $url =3D $request->to_url()."&oauth_signature=3D$OAuthConsumerSecret%26$oau=
    th_token_secret";
    =A0=A0=A0 //.$signature->build_signature( $request, new OAuthConsumer('', $=
    OAuthConsumerSecret), new OAuthToken('', $oauth_token_secret));
    $ch =3D curl_init();
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $ch, CURLOPT_URL, $url );
    $resp =3D curl_exec( $ch );
    curl_close($ch);
    unset($oauth_token);
    unset($oauth_token_secret);
    parse_str($resp);
    if (!$oauth_token || !$oauth_token_secret) {
    =A0=A0=A0 throw new Exception($resp);=A0=A0=A0=20
    }
    0
  • // 4) Get Authorization header



    // 4a) for YMWS SOAP endpoint

    $request =3D new OAuthRequest('POST', "$endPoint/soap", array(

    =A0=A0=A0 'oauth_nonce'=3D>mt_rand(),

    =A0=A0=A0 'oauth_timestamp'=3D>time(),

    =A0=A0=A0 'oauth_version'=3D>'1.0',

    =A0=A0=A0 'oauth_signature_method'=3D>'HMAC-SHA1',

    =A0=A0=A0 'oauth_consumer_key'=3D>$OAuthConsumerKey,

    =A0=A0=A0 'oauth_token'=3D>$oauth_token

    =A0=A0=A0 ));

    $request->sign_request($signature, new OAuthConsumer('', $OAuthConsumerSecr=

    et), new OAuthToken('', $oauth_token_secret));

    $oauthURLForSoap =3D $request->to_url();



    // 4b) for YMWS JSONRPC endpoint

    $request =3D new OAuthRequest('POST', "$endPoint/jsonrpc", array(

    =A0=A0=A0 'oauth_nonce'=3D>mt_rand(),

    =A0=A0=A0 'oauth_timestamp'=3D>time(),

    =A0=A0=A0 'oauth_version'=3D>'1.0',

    =A0=A0=A0 'oauth_signature_method'=3D>'HMAC-SHA1',

    =A0=A0=A0 'oauth_consumer_key'=3D>$OAuthConsumerKey,

    =A0=A0=A0 'oauth_token'=3D>$oauth_token

    =A0=A0=A0 ));

    $request->sign_request($signature, new OAuthConsumer('', $OAuthConsumerSecr=

    et), new OAuthToken('', $oauth_token_secret));

    $oauthURLForJson =3D $request->to_url();



    // 5) Call YMWS



    if(strtoupper($argv[1]) =3D=3D "JSON")

    {

    =A0=A0=A0 $jsonClient =3D new JsonRpcClient($oauthURLForJson, NULL);

    =A0=A0=A0 $jsonClient->__setHeader(array('Content-Type: application/json'))=

    ;

    =A0=A0=A0 var_dump($jsonClient->DownloadAttachment(new stdclass()));

    }

    else if(strtoupper($argv[1]) =3D=3D "SOAP")

    {

    =A0=A0=A0 $url =3D 'http://mail.yahooapis.com/ya/download/fid=3DInbox&mid=

    =3D1_38188_AJ%2FPjkQAAEkmRE%2Fa9wVAADkU97c&pid=3D2&clean=3D0&inline=3D0';

    =A0=A0=A0=20

    =A0=A0=A0 $ch =3D curl_init();

    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

    curl_setopt( $ch, CURLOPT_URL, $url );

    $resp =3D curl_exec( $ch );

    curl_close($ch);



    echo $resp;

    }
    0

Recent Posts

in Yahoo! Mail Web Services API