Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Аутентифицируемся при загрузке странички
                if (!IsPostBack)
                {
                    var yahoo = new WebConsumer(YahooConsumer.ServiceDescription, this.TokenManager);

                    // Is Google calling back with authorization?
                    var accessTokenResponse = yahoo.ProcessUserAuthorization();
                    if (accessTokenResponse != null)
                    {
                        AccessToken = accessTokenResponse.AccessToken;
                        YahooGuid   = accessTokenResponse.ExtraData["xoauth_yahoo_guid"];
                        //Redirecting to result page
                        Response.Redirect("YahooAddressBook.aspx");
                    }
                    // If we don't yet have access, immediately request it.
                    YahooConsumer.RequestAuthorization(yahoo);
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                SubmitError(ex.Message);
            }
        }
Пример #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (!IsPostBack && !string.IsNullOrEmpty(AccessToken))
         {
             var          google           = new WebConsumer(YahooConsumer.ServiceDescription, TokenManager);
             XDocument    contactsDocument = YahooConsumer.GetContacts(google, AccessToken, YahooGuid);
             const string xmlns            = "http://social.yahooapis.com/v1/schema.rng";
             var          contacts         = from entry in contactsDocument.Root.Elements(XName.Get("contact", xmlns))
                                             select
                                             new
             {
                 Name = from field in entry.Elements(XName.Get("fields", xmlns))
                        where field.Element(XName.Get("type", xmlns)).Value == "name"
                        select field.Element(XName.Get("value", xmlns)).Element(XName.Get("givenName", xmlns)).Value,
                 LastName = from field in entry.Elements(XName.Get("fields", xmlns))
                                where field.Element(XName.Get("type", xmlns)).Value == "name"
                            select field.Element(XName.Get("value", xmlns)).Element(XName.Get("familyName", xmlns)).Value,
                 Email = from field in entry.Elements(XName.Get("fields", xmlns))
                             where field.Element(XName.Get("type", xmlns)).Value == "email"
                         select field.Element(XName.Get("value", xmlns)).Value,
             };
             foreach (var contact in contacts)
             {
                 AddContactInfo(contact.Name.FirstOrDefault(), contact.LastName.FirstOrDefault(), contact.Email);
             }
             SubmitData();
         }
         else
         {
             Response.Redirect("YahooImport.aspx");
         }
     }
     catch (System.Threading.ThreadAbortException)
     {
     }
     catch (Exception ex)
     {
         ErrorScope = ex.Message;
         SubmitData();
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    //if (AccessToken!=null)
                    //{
                    //    Response.Redirect("YahooAddressBook.aspx");
                    //}

                    var yahoo = new WebConsumer(YahooConsumer.ServiceDescription, this.TokenManager);

                    // Is Google calling back with authorization?
                    var accessTokenResponse = yahoo.ProcessUserAuthorization();
                    if (accessTokenResponse != null)
                    {
                        this.AccessToken = accessTokenResponse.AccessToken;
                        this.YahooGuid   = accessTokenResponse.ExtraData["xoauth_yahoo_guid"];
                        //Redirecting to result page
                        Response.Redirect("YahooAddressBook.aspx");
                    }
                    //else if (this.AccessToken == null)
                    //{
                    // If we don't yet have access, immediately request it.
                    YahooConsumer.RequestAuthorization(yahoo);
                    //}
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                ErrorScope = ex.Message;
                SubmitData();
            }
        }