FlickrNet 从相册中获取照片

FlickrNet Get Photos From Albums

我在这里有点难过,因为 Flickr 文档提到了 Collections 和画廊,但我没有找到与相册相关的内容。

我正在 asp.net 中建立一个网站,并想从我拥有的 Flickr 相册中加载照片,一段时间后检查 Collections 和图库 API 但没有成功,我我希望有人知道如何从 Flickr 相册中检索照片。

这是我目前拥有的,它适用于我的照片流中的照片,但我还没有弄清楚如何加载相册。

using System;
using System.Configuration;
using System.Web;
using FlickrNet;

namespace MyWebSite.Core.Gateways
{
    public class FlickrGateway : IFlickrGateway
    {
        private readonly string _flickrApiKey = ConfigurationManager.AppSettings["Flickr.ApiKey"];
        private readonly string _flickrApiSecret = ConfigurationManager.AppSettings["Flickr.ApiSecret"];
        private readonly string _flickrApiUserId = ConfigurationManager.AppSettings["Flickr.ApiUserId"];
        private readonly string _flickrPhotoSetId = ConfigurationManager.AppSettings["Flickr.PhotoSetId"];

        private readonly Flickr _flickrApi;

        public FlickrGateway()
        {
            _flickrApi = new Flickr(_flickrApiKey, _flickrApiSecret) { InstanceCacheDisabled = true };

            if (OAuthToken == null) return;

            _flickrApi.OAuthAccessToken = OAuthToken.Token;
            _flickrApi.OAuthAccessTokenSecret = OAuthToken.TokenSecret;
        }

        public PhotoCollection GetPhotoStream()
        {
            return _flickrApi.PeopleGetPublicPhotos(_flickrApiUserId);
        }

        public PhotosetCollection GetPhotosetsList()
        {
            return _flickrApi.PhotosetsGetList(_flickrApiUserId);
        }

        public PhotosetPhotoCollection GetPhotoSet(string photoSetId)
        {
            return _flickrApi.PhotosetsGetPhotos(photoSetId);
        }

        public PhotosetPhotoCollection GetPhotoSet()
        {
            return _flickrApi.PhotosetsGetPhotos(_flickrPhotoSetId);
        }

        private static OAuthAccessToken OAuthToken
        {
            get
            {
                if (HttpContext.Current.Request.Cookies["OAuthToken"] == null)
                {
                    return null;
                }
                var values = HttpContext.Current.Request.Cookies["OAuthToken"].Values;
                return new OAuthAccessToken
                {
                    FullName = values["FullName"],
                    Token = values["Token"],
                    TokenSecret = values["TokenSecret"],
                    UserId = values["UserId"],
                    Username = values["Username"]
                };
            }
            set
            {
                var cookie = new HttpCookie("OAuthToken")
                {
                    Expires = DateTime.UtcNow.AddHours(1),
                };
                cookie.Values["FullName"] = value.FullName;
                cookie.Values["Token"] = value.Token;
                cookie.Values["TokenSecret"] = value.TokenSecret;
                cookie.Values["UserId"] = value.UserId;
                cookie.Values["Username"] = value.Username;
                HttpContext.Current.Response.AppendCookie(cookie);
            }
        }
    }
}

要获取相册照片,您需要调用 flickr.photosets.getPhotos API 方法。

.NetAPI中对应的方法是Flickr_Photosets.PhotosetsGetPhotos。 如我所见,您已经拥有它:GetPhotoSet

因此,您只需将 albumId 作为 photoSetId 传递即可。