0

Fetch the contacts using Contacts API in C#?

Hello All,

Can anybody please provide me with the steps to fetch the yahoo contact list using Yahoo contacts API.I have almost stuck with this issue from long time.When i am trying to get the Oauth token by using the following method it is giving me unauthorized error in the first step itself.Please,help me solve this issue.

OAuthBase oAuth = new OAuthBase();
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string outURL = string.Empty;
//string sig = oAuth.GenerateSignature(uri,
// consumerKey, consumerSecret,
// string.Empty, string.Empty,
// "GET", timeStamp, nonce,
// OAuthBase.SignatureTypes.HMACSHA1, out outURL, out sig);

//sig = HttpUtility.UrlEncode(sig);
string normalizedUrl;
string normalizedRequestParameters;

string YahooOAuthToken = "T6LJ4IXC7WXHSCUYV3I2H6YADI";
Uri GetYahooContacts = new Uri("http://social.yahooapis.com/v1/user/" + YahooOAuthToken + "/contacts");

//OAuthBase oAuth = new OAuthBase();
string EncodedSIG = oAuth.GenerateSignature(GetYahooContacts, consumerKey, consumerSecret, YahooOAuthToken, consumerSecret, "GET", timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);

string authHeader = "Authorization:OAuth" +
"realm =\"http://yahooapis.com\"" +
",oauth_consumer_key=\"" + consumerKey + "\"" +
",oauth_nonce=\"" + nonce + "\"" +
",oauth_signature_method=\"HMAC-SHA1\"" +
",oauth_timestamp=\"" + timeStamp + "\"" +
",oauth_token=\"" + YahooOAuthToken + "\"" +
",oauth_version=\"1.0\"" +
",oauth_signature=\"" + EncodedSIG + "\"";

HttpWebRequest request = WebRequest.Create(GetYahooContacts.ToString()) as HttpWebRequest;

request.Headers.Add(authHeader);

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader YahooContactsList = new StreamReader(response.GetResponseStream());
string YahooContacts = YahooContactsList.ReadToEnd();
// MessageBox.Show(YahooContacts);
//MessageBox.Show("Finally Success");
lblMessage.Text = "Success";
}
}

Any help would be greatly appreciated.
Waiting for reply.

Thanks & Regards

by
  • US
  • Feb 18, 2010
1 Reply
  • Hi, I Think the problem is OAuthBase 's not reliable. I also face same problem as yours. And I use an other oauth lib for C# is http://oauth-dot-net.googlecode.com/files/...rce-0.7.1.0.zip and i request token successully
    Good luck!


    QUOTE (Ushasree @ Feb 18 2010, 04:20 AM) <{POST_SNAPBACK}>
    Hello All,

    Can anybody please provide me with the steps to fetch the yahoo contact list using Yahoo contacts API.I have almost stuck with this issue from long time.When i am trying to get the Oauth token by using the following method it is giving me unauthorized error in the first step itself.Please,help me solve this issue.

    OAuthBase oAuth = new OAuthBase();
    string nonce = oAuth.GenerateNonce();
    string timeStamp = oAuth.GenerateTimeStamp();
    string outURL = string.Empty;
    //string sig = oAuth.GenerateSignature(uri,
    // consumerKey, consumerSecret,
    // string.Empty, string.Empty,
    // "GET", timeStamp, nonce,
    // OAuthBase.SignatureTypes.HMACSHA1, out outURL, out sig);

    //sig = HttpUtility.UrlEncode(sig);
    string normalizedUrl;
    string normalizedRequestParameters;

    string YahooOAuthToken = "T6LJ4IXC7WXHSCUYV3I2H6YADI";
    Uri GetYahooContacts = new Uri("http://social.yahooapis.com/v1/user/" + YahooOAuthToken + "/contacts");

    //OAuthBase oAuth = new OAuthBase();
    string EncodedSIG = oAuth.GenerateSignature(GetYahooContacts, consumerKey, consumerSecret, YahooOAuthToken, consumerSecret, "GET", timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);

    string authHeader = "Authorization:OAuth" +
    "realm =\"http://yahooapis.com\"" +
    ",oauth_consumer_key=\"" + consumerKey + "\"" +
    ",oauth_nonce=\"" + nonce + "\"" +
    ",oauth_signature_method=\"HMAC-SHA1\"" +
    ",oauth_timestamp=\"" + timeStamp + "\"" +
    ",oauth_token=\"" + YahooOAuthToken + "\"" +
    ",oauth_version=\"1.0\"" +
    ",oauth_signature=\"" + EncodedSIG + "\"";

    HttpWebRequest request = WebRequest.Create(GetYahooContacts.ToString()) as HttpWebRequest;

    request.Headers.Add(authHeader);

    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
    StreamReader YahooContactsList = new StreamReader(response.GetResponseStream());
    string YahooContacts = YahooContactsList.ReadToEnd();
    // MessageBox.Show(YahooContacts);
    //MessageBox.Show("Finally Success");
    lblMessage.Text = "Success";
    }
    }

    Any help would be greatly appreciated.
    Waiting for reply.

    Thanks & Regards
    0

Recent Posts

in Contacts