0

downloading an attachment via Yahoo! Mail API

Hello, I am having issues with downloading an attachment via the API for Yahoo! Mail.

I have used several different Oauth libraries and have recently tested code (http://nullinfo.wordpress.com/oauth-yahoo/) for CallContact, which does work.

I am using the data generated from CallContact to download an attachment and the sent header and response are below:

GET /ya/download?mid=1_14882_AMvJjkQAAJJjTQgZpgDJg1E%252FJsk&fid=Inbox&pid=2&clean=0&inline=0 HTTP/1.1
Host: mail.yahooapis.com
Accept: */*
Authorization: OAuth realm="yahooapis.com",oauth_version="1.0",oauth_nonce="1890108292",oauth_timestamp="1294189375",oauth_consumer_key="...",oauth_token="A%3D7haljcPKlDiLigYC7eZ6af8lD_yXf_lh2fxl.SnsPPmh.N4FR8LKOWrEjC7h1qC4KOhwBfP8Ynz190
ecUDM5f6rsYUSsn1iUUresRql6Uqlbn2x3BZHZkbCJWPuBNxT9vYYHKUWdKJs_nGeG.AwXFs9YmB2sPuF
9Lrqf1Jq0qdKZysw6EY2SteTrJGVG3eCT95qe2JU6YhQAOzuh_.3A3uFivT3srxeeqpDnjtTATlG3cHyX
.dhcGoVv45qe6TJHsHWvehW7nmjmmi0LpKrZpDJz_4JneNrU0QynQnmIwXmsTcaAWAgs_sKQrsh0121mg
T8gDpjKfkeqX6ER.KdxmFzzajphBvpLUmaIKXj4HEoiDIIKMElPTXJKZ5J9ZHlWTDqykkqCUoQvbTVv67
J1FEq_nshkJLcRakdy2njPxVYP.KhXBlok7CU.0JHbGVIhPfffNbUkSGWHVXhf1oXGdn9PrSHZ05EglRe
QX.YbWACc6yR4D0BtROlqgJWNkhuE1hpg_TfHiDZNxJ7Qch2A6geMwn8x_E3kZgn75PkHqEFbgGJpd9_5
pkL1ry4ag5nyNfCyqQGDvVfNOk3511aelS82hH5NG.qVRT8KtlOHNKm3IR3lmeoeqSJXBbhbFLl49Dj2f
QyIMmn3peT340aWOPhdFWd1yhyEHa95_zMB2Qq0KJFdKp9sxVShRr_0YDQxhDdKHx8sBU21hgzkXHHmTk
ji9AfSlZh1giYYz2BBBr3vWMVpZY0RJp4X67JApXBju1IeB.u8Xvbd.q7.aR8-",oauth_signature_method="HMAC-SHA1",oauth_signature="lO%2FnmSh7frpRHi%2BV8S5EmieH2Tc%3D"

Response headers:

HTTP/1.1 404 Not Found
Date: Wed, 05 Jan 2011 01:02:40 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

The mid has been encoded and the URL is correct and is based on the documentation. Is there something that I am missing that the documentation does not cover??

Thank you.


Sincerely,
Obiora

by
1 Reply
  • Asi,

    I did figure it out back in February of this year and have done a lot of other programming since then, so I don't recall specifically what was wrong, so I am just going to include the working program below:

    <?php

    //Libraries used for accessing YMail api's.
    require_once 'OAuth.php';
    require_once 'JsonRpcClient.inc';

    //Endpoint for Yahoo mail WSDL
    $endPoint = 'http://mail.yahooapis.com/ws/mail/v1.1';

    //OAuth Endpoint
    $OAuthEndPoint = 'https://api.login.yahoo.com/oauth/v2';

    //You can get these keys from YDN.
    $OAuthConsumerKey = '';
    $OAuthConsumerSecret = '';

    // see http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html
    $signature = new OAuthSignatureMethod_HMAC_SHA1();

    // 1) Get Request Token
    $request = new OAuthRequest('GET', "$OAuthEndPoint/get_request_token", array(
        'oauth_consumer_key'=>$OAuthConsumerKey,
        'oauth_signature_method'=>'PLAINTEXT',
        'oauth_version'=>'1.0',
        'oauth_timestamp'=>time(),   
        'oauth_nonce'=>mt_rand(),
        'oauth_callback'=>'oob'));
    $url = $request->to_url()."&oauth_signature=$OAuthConsumerSecret%26";

    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $ch, CURLOPT_URL, $url );
    $resp = curl_exec( $ch );
    curl_close($ch);
    parse_str($resp,$tokens);
    $oauth_token = $tokens['oauth_token'];
    $oauth_token_secret = $tokens['oauth_token_secret'];

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

    // 2) Get User Auth
    echo " Open this Url in your browser ->> $OAuthEndPoint/request_auth?oauth_token=$oauth_token \n";
    echo " This should be provided to end users of your application.End users should provide their
    '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 = trim(fgets(STDIN));

    // 3) Get Access Token
    $request = new OAuthRequest('GET', "$OAuthEndPoint/get_token", array(
        'oauth_consumer_key'=>$OAuthConsumerKey,   
        'oauth_signature_method'=>'PLAINTEXT',
        'oauth_version'=>'1.0',
        'oauth_verifier'=>$oauth_verifier,
        'oauth_token'=>$oauth_token,   
        'oauth_timestamp'=>time(),   
        'oauth_nonce'=>mt_rand(),   
        ));
    $url = $request->to_url()."&oauth_signature=$OAuthConsumerSecret%26$oauth_token_secret";

    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $ch, CURLOPT_URL, $url );
    $resp = curl_exec( $ch );
    curl_close($ch);

    parse_str($resp);
    if (!$oauth_token || !$oauth_token_secret) {
        throw new Exception($resp);   
    }

    $mid = ''; //i.e., 1_68195_AMvJjkQAAJJjTQgZpgDJg1E%2FJsk

    $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);
    if ( curl_errno($ch)) {
        $code = 0;
    }
    else {
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    }

    echo "\n\n".$header; //header contains the attachment--simple way of getting attachment

    $file = ''; //i.e., file.pdf
    $fh = fopen($file, 'w') or die("can't open file");
    fwrite($fh, $header);
    fclose($fh);

    curl_close($ch);

    exit(0);



    QUOTE(Asi Shmaiser @ 24 Sep 2011 9:21 AM)
    great to here, so maybe you can help me out :)
    I didn't understand what's the solution - 

    1. did u use an OAuth Authorization header or sent all the oauth parameters in the url?
    2. should the signature contains the regular params (mid, fid... ) or just the basic url + oauth parameters?

    this is my request:

    http://mail.yahooapis.com/ya/download?clean=0&fid=Inbox&inline=0&mid=1_22_1_4931_0_AIHTimIAAAG0Tmsv5AzWR1FOqEA&pid=2&oauth_consumer_key=..............&oauth_nonce=8016381357093189350&oauth_signature=EcZSH5%2B6ny6U%2BHWAmLgWG9RXQlk%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1316881005&oauth_token=A%3DkOSQRMrSmwPrWniqY02.4qxYoKKD61EIL19M9uDuBvRBbtxCiRVx7jJum3cV6ebWNdM0zDF7sU2ezKPa2Y6cT9ZJIlazRBkxhasb_l1n3I_DmRY48drpYDMB2g4IEPZF355iOQ7FGIJaxTCT6E1nJSlmgqbx7zmrJHOe43qiyhWWSVNOLzVWUjAWdTUYN4jJ3hodR1o.55sbHlBIdq.L.lmR5D4VS7tBbqg7mt9t9gclib3s17JNwmvX.8s7OJRQ5fZMBbxWaTKytcnl_DaNlUAljYX6yEbaxkTmOMB7fNrEFeexklpNfAlTy8.rmVAddLh8J0vI12hNYYuuPRRXzMrSgDoDV27x1AsiMDt1fJWj43Sd3NPvmmwCCXwxwCXn0ad_1h.YJPUqyJxEwxuYFK85XdrHpfeULgwth6Fukh7PaC5v9jvQOQR9p_wDIHJKuBFcmZkjlp7h1ID0Y08WbdMotaX1qMkbPmMvPhX7AV8VfasFxj3vo3.MVmc6ndWLPAXX0ep6EkNrpBZadI6tK_5a213QvRPlZcneCcdXWJWD5BpyDrMXdyVdMMC5bB6jQ0jBEN9GmxbMuvt9Xo0N8IlKLJII7jfmZZpPjC8V8HklHbpOOQaDsGU1muDdNAgPKi6qp53ZH5.TuUd7X3C_51pvPC0uopJaAs7SE9XBEVjCNeEZ9jkbJuRoUgTkoBcZTNa6PJXH7j9q5NZ4KTiL2z2Kjq_3fPrO3U0plPn7cF.T0UmqLwhtZisL1HouwQ--&oauth_version=1.0

    I keep getting 404 Not Found for that request. 
    If I drop the mid,fid.. params I get "500 unable_to_get_message_info_or_part".

    other calls to the Yahoo mail web services are working just fine with the oauth mechanism...
    any ideas?

    thank a lot,
    Asi.

    QUOTE(Obiora @ 23 Sep 2011 5:09 PM)
    Yes, I did resolve the problem.

    Thank you for checking in with me.

    QUOTE(Asi Shmaiser @ 23 Sep 2011 2:10 AM)
    Hi Obiora,
    did u manage to solve the download problem?

    QUOTE(Obiora @ 4 Jan 2011 5:06 PM)
    Hello, I am having issues with downloading an attachment via the API for Yahoo! Mail.

    I have used several different Oauth libraries and have recently tested code (http://nullinfo.wordpress.com/oauth-yahoo/) for CallContact, which does work.

    I am using the data generated from CallContact to download an attachment and the sent header and response are below:

    GET /ya/download?mid=1_14882_AMvJjkQAAJJjTQgZpgDJg1E%252FJsk&fid=Inbox&pid=2&clean=0&inline=0 HTTP/1.1
    Host: mail.yahooapis.com
    Accept: */*
    Authorization: OAuth realm="yahooapis.com",oauth_version="1.0",oauth_nonce="1890108292",oauth_timestamp="1294189375",oauth_consumer_key="...",oauth_token="A%3D7haljcPKlDiLigYC7eZ6af8lD_yXf_lh2fxl.SnsPPmh.N4FR8LKOWrEjC7h1qC4KOhwBfP8Ynz190
    ecUDM5f6rsYUSsn1iUUresRql6Uqlbn2x3BZHZkbCJWPuBNxT9vYYHKUWdKJs_nGeG.AwXFs9YmB2sPuF
    9Lrqf1Jq0qdKZysw6EY2SteTrJGVG3eCT95qe2JU6YhQAOzuh_.3A3uFivT3srxeeqpDnjtTATlG3cHyX
    .dhcGoVv45qe6TJHsHWvehW7nmjmmi0LpKrZpDJz_4JneNrU0QynQnmIwXmsTcaAWAgs_sKQrsh0121mg
    T8gDpjKfkeqX6ER.KdxmFzzajphBvpLUmaIKXj4HEoiDIIKMElPTXJKZ5J9ZHlWTDqykkqCUoQvbTVv67
    J1FEq_nshkJLcRakdy2njPxVYP.KhXBlok7CU.0JHbGVIhPfffNbUkSGWHVXhf1oXGdn9PrSHZ05EglRe
    QX.YbWACc6yR4D0BtROlqgJWNkhuE1hpg_TfHiDZNxJ7Qch2A6geMwn8x_E3kZgn75PkHqEFbgGJpd9_5
    pkL1ry4ag5nyNfCyqQGDvVfNOk3511aelS82hH5NG.qVRT8KtlOHNKm3IR3lmeoeqSJXBbhbFLl49Dj2f
    QyIMmn3peT340aWOPhdFWd1yhyEHa95_zMB2Qq0KJFdKp9sxVShRr_0YDQxhDdKHx8sBU21hgzkXHHmTk
    ji9AfSlZh1giYYz2BBBr3vWMVpZY0RJp4X67JApXBju1IeB.u8Xvbd.q7.aR8-",oauth_signature_method="HMAC-SHA1",oauth_signature="lO%2FnmSh7frpRHi%2BV8S5EmieH2Tc%3D"

    Response headers:

    HTTP/1.1 404 Not Found
    Date: Wed, 05 Jan 2011 01:02:40 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

    The mid has been encoded and the URL is correct and is based on the documentation. Is there something that I am missing that the documentation does not cover??

    Thank you.


    Sincerely,
    Obiora
    0
This forum is locked.

Recent Posts

in YDN Documentation