Thanks for your reply Eric... I still cann't make this work. Here are the steps I'm following
1. I buil the Url Endpoint for download with the parameters:
http://mail.yahooapis.com/ya/download?mid=...=0&inline=1I stored this url on a variable called Url.
2. Then I call Eric's function like this:
CODE
var req = buildWebRequest(apiAccessToken, oauthTokenSecret, Url, "GET");
The details of the function are (I also tried without oauth_session_handle as it is on Eric's original version)
CODE
private System.Net.WebRequest buildWebRequest(string strAuthToken, string strAuthTokenSecret, string url, string strMethod)
{
OAuthBase OAuthBase = new OAuthBase();
var webRequest = HttpWebRequest.Create(url);
string strNonce = OAuthBase.GenerateNonce();
string strTimestamp = OAuthBase.GenerateTimeStamp();
string strConsumerKey = System.Configuration.ConfigurationManager.AppSettings ["ConsumerKey"];
string strConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];
string p, h;
Uri uri = new Uri(url);
string strSignature = OAuthBase.GenerateSignature(uri, strConsumerKey, strConsumerSecret, strAuthToken, strAuthTokenSecret, strMethod, strTimestamp, strNonce, out p , out h);
webRequest.Headers.Add("Authorization", "OAuth oauth_nonce=" + (char)34 + strNonce + (char)34 +
", oauth_timestamp=" + (char)34 + strTimestamp + (char)34 +
", oauth_version=" + (char)34 + "1.0" + (char)34 +
", oauth_signature_method=" + (char)34 + "HMAC-SHA1" + (char)34 +
", oauth_consumer_key=" + (char)34 + strConsumerKey + (char)34 +
", oauth_token=" + (char)34 + strAuthToken + (char)34 +
", oauth_signature=" + (char)34 + strSignature + (char)34 +
", oauth_session_handle=" + (char)34 + OAuthHelper.Instance.OauthSessionHandle + (char)34);
return webRequest;
}
3. I try to get the bytes with this code, but on the using it raises the exception, which I catch and try to view the response which returns a "not found"... I tried several emails with attachments on several accounts and can't get it to work... please help.
CODE
string Response="";
try
{
using (HttpWebResponse hr = (HttpWebResponse)req.GetResponse())
{
Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader loResponseStream = new
StreamReader(hr.GetResponseStream(), enc);
Response = loResponseStream.ReadToEnd();
loResponseStream.Close();
}
} catch (WebException ex)
{
HttpWebResponse response = ex.Response as HttpWebResponse;
}
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
return encoding.GetBytes(Response);
Carlos-
The 404 is definitely an oauth failure. I haven't called DownloadAttachment before, but I don't think any of the APIs support passing ouath parameters in the query string. Try adding them as an Authorization header instead. If you see my code at http://github.com/ecastelli/Oauth-for-Yaho...-Social-in-.NET, take a look my buildWebRequest function in AddContactToAddressBookSocialAPI.aspx.vb. This should add the required headers for you and hopefully fix the problem.
Let me know how it turns out.
Eric