예제 #1
0
        /// <summary>
        /// Load page with query string of Flickr and get logged user
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                // Verify if query string contains authentication values
                if (Request.QueryString["oauth_verifier"] != null && Session["RequestToken"] != null)
                {
                    Flickr            flickr       = FlickrManager.GetInstance();
                    OAuthRequestToken requestToken = Session["RequestToken"] as OAuthRequestToken;
                    try
                    {
                        OAuthAccessToken accessToken = flickr.OAuthGetAccessToken(requestToken, Request.QueryString["oauth_verifier"]);
                        FlickrManager.OAuthToken = accessToken;
                    }
                    catch (OAuthException)
                    {
                        Debug.Write("[ERROR] - Error to get Flickr access token.");
                    }
                }

                // Verify if not post back
                if (!Page.IsPostBack)
                {
                    SetLogged();
                }
            }
            catch (System.Exception)
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Ocorreu um erro ao carregar as fotos.');", true);
            }
        }
예제 #2
0
        /// <summary>
        /// Flickr login button clicked
        /// </summary>
        protected void ibtnAuthenticate_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Flickr            flickr = FlickrManager.GetInstance();
                OAuthRequestToken token  = flickr.OAuthGetRequestToken(Request.Url.AbsoluteUri);

                Session["RequestToken"] = token;

                string url = flickr.OAuthCalculateAuthorizationUrl(token.Token, AuthLevel.Read);
                Response.Redirect(url);
            }
            catch (System.Exception)
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Ocorreu um erro ao fazer login.');", true);
            }
        }
예제 #3
0
        /// <summary>
        /// Method responsible for getting and analyzing images
        /// </summary>
        private void GetPhotostream()
        {
            try
            {
                // Public  user Id for this sample
                string userId        = ConfigurationManager.AppSettings["FlickrDefaultKey"];
                int    photosPerPage = int.Parse(ConfigurationManager.AppSettings["FlickrPhotoPerPage"]);

                Flickr          flickr = FlickrManager.GetAuthInstance();
                PhotoCollection photos;

                if (FlickrManager.OAuthToken != null)
                {
                    userId = FlickrManager.OAuthToken.UserId;
                    photos = flickr.PeopleGetPublicPhotos(userId, 0, photosPerPage, SafetyLevel.None, PhotoSearchExtras.PathAlias);
                }
                else
                {
                    // If not logged, get photos from public group
                    photos = flickr.GroupsPoolsGetPhotos(userId, 0, photosPerPage);
                }

                var list = photos.ToList();

                ItemList = new List <Item>();

                if (list != null && list.Count > 0)
                {
                    foreach (var photo in list)
                    {
                        Item item = new Item();
                        item.URL = photo.LargeUrl;

                        ItemList.Add(item);
                    }
                }

                rptImages.DataSource = ItemList;
                rptImages.DataBind();
            }
            catch (System.Exception)
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Ocorreu um erro ao carregar as fotos.');", true);
            }
        }