0

Import contact from yahoo in asp.net

Hi,

I am using asp.net c# to import contact from yahoo. I am getting this error

The remote server returned an error: (403) Forbidden. According to yahoo developer center, I have alreadey changes the protocol from http to https . I am using this code to retrieve contact so please tell me where, I am doing wrong.

DataTable dt = new DataTable(); dt.Columns.Add("Email"); dt.Columns.Add(new DataColumn("FirstName", typeof(string))); dt.Columns.Add(new DataColumn("LastName", typeof(string))); string FirstName = ""; string LastName = "";

    OAuthBase oauth = new OAuthBase();
  **  Uri uri = new Uri("<https://social.yahooapis.com/v1/user/>" + OauthYahooGuid + "/contacts?format=XML");**

    string nonce = oauth.GenerateNonce();
    string timeStamp = oauth.GenerateTimeStamp();
    string normalizedUrl;
    string normalizedRequestParameters;
    string sig = oauth.GenerateSignature(uri, ConsumerKey, ConsumerSecret, OauthToken, OauthTokenSecret, "GET", timeStamp, nonce, OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out normalizedRequestParameters);

    StringBuilder sbGetContacts = new StringBuilder(uri.ToString());
    Response.Write("<br/>Signature:" + sig);
    Response.Write("<br/>OauthYahooGuid:" + OauthYahooGuid);
    Response.Write("<br/>");
    Response.Write("URL: " + sbGetContacts.ToString());
    //Response.End();

    try
    {
        string returnStr = string.Empty;
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sbGetContacts.ToString());
        req.Method = "GET";

        string authHeader = "Authorization: OAuth " +
        "realm=\"yahooapis.com\"" +
        ",oauth_consumer_key=\"" + ConsumerKey + "\"" +
        ",oauth_nonce=\"" + nonce + "\"" +
        ",oauth_signature_method=\"HMAC-SHA1\"" +
        ",oauth_timestamp=\"" + timeStamp + "\"" +
        ",oauth_token=\"" + OauthToken + "\"" +
        ",oauth_version=\"1.0\"" +
        ",oauth_signature=\"" + HttpUtility.UrlEncode(sig) + "\"";

        //Response.Write("</br>Headers: " + authHeader);

        req.Headers.Add(authHeader);

        HttpWebResponse res = (HttpWebResponse)req.GetResponse();

        StreamReader streamReader = new StreamReader(res.GetResponseStream());
        returnStr = streamReader.ReadToEnd();
        res.Close();
        //ErrorLog.WriteLog("oAuthYahoo.aspx", "RetrieveContacts", "xml", returnStr, Request.RawUrl);
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.LoadXml(returnStr);
        XmlNodeReader xmlread=new XmlNodeReader(xmldoc);
        DataSet ds = new DataSet();
        ds.ReadXml(xmlread);
        XmlNodeList elemList = xmldoc.DocumentElement.GetElementsByTagName("fields");



        for (int i = 0; i < elemList.Count; i++)
        {
            DataRow dr = dt.NewRow();


            if (elemList[i].ChildNodes[1].InnerText == "email" )
            {
                dr["Email"] = elemList[i].ChildNodes[2].InnerText;

                //if (elemList[i].ChildNodes[1].InnerText == "name")
                if (i+1 < elemList.Count)
                {
                    dr["FirstName"] = ds.Tables[3].Rows[i + 1]["givenName"].ToString();
                    dr["LastName"] = ds.Tables[3].Rows[i + 1]["familyName"].ToString();
                }
                //string[] names = elemList[i + 2].ChildNodes[2].InnerText.ToString().Trim().Split(new char[] { ' ' }, 2);
                //if (names.Length == 1)
                //{
                //    FirstName = "";
                //    LastName = names[0];
                //    dr["LastName"] = names[0]; ;// t.Title;
                //}
                //else
                //{
                //    dr["FirstName"] = names[0];
                //    FirstName = names[0];
                //    dr["LastName"] = names[1];
                //}
                dt.Rows.Add(dr);
            }

        }

by
5 Replies
  • I've read several forum threads and I'm using the a very similar code without any success, and I'm alway getting the same error as you.

    If somebody will able to solve this issue, please answer!

    1
  • I'm using the same class OAuthBase.cs, available in https://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs. I am able to get the access token and yahoo guid, but not the contacts. The remote server returned an error: (401), with the message invalid token... Somebody would help me with this issue? Yahoo team, any idea?

    1
  • I cannot send messages. I can receive them but people are not receiving mine. I had uninstalled and re installed. Any suggestions?

    0
  • I'm using the same class OAuthBase.cs, available in https://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs. I am able to get the access token and yahoo guid, but not the contacts. Please suggest....

    0
  • I've read several forum threads and I'm using the a very similar code without any success, and I'm alway getting the same error as you.

    0

Recent Posts

in Messenger IM SDK