FlickrNet開發系列- FlickrNet基本功能開發(一)
MessageBox.Show(string.Format(
@“FullName: {0} UserId: {1} UserName: {2}”, user.FullName, user.UserId, user.UserName)); }
var photoSets = m_Flickr.PhotosetsGetList(userID);
foreach (var photoSet in photoSets)
{
var pic = new PictureBox() { ImageLocation = photoSet.PhotosetThumbnailUrl, BorderStyle = BorderStyle.FixedSingle, SizeMode = PictureBoxSizeMode.AutoSize };
container.Controls.Add(pic);
}
var photos = m_Flickr.PhotosGetNotInSet();
foreach (var photo in photos)
{
var pic = new PictureBox() { ImageLocation = photo.ThumbnailUrl, SizeMode = PictureBoxSizeMode.AutoSize };
container.Controls.Add(pic);
}
form.Controls.Add(container);
form.ShowDialog();
}</pre>
foreach (var photo in photos)
{
var pic = new PictureBox() { ImageLocation = photo.ThumbnailUrl, BorderStyle = BorderStyle.FixedSingle, SizeMode = PictureBoxSizeMode.AutoSize };
container.Controls.Add(pic);
}
form.Controls.Add(container);
form.ShowDialog();
}</pre>
namespace Flickr.NET_Demo { public partial class Form1 : Form { #region Property public FlickrNet.Flickr m_Flickr { get; set; } public FlickrNet.Auth m_Auth { get; set; } #endregion
#region Constructor
public Form1()
{
InitializeComponent();
}
#endregion
#region Private Method
private void Login()
{
m_Flickr = new FlickrNet.Flickr(tbxAPIKey.Text, tbxSecret.Text);
var frob = m_Flickr.AuthGetFrob();
string url = m_Flickr.AuthCalcUrl(frob, FlickrNet.AuthLevel.Read | FlickrNet.AuthLevel.Write);
Form loginDlg = new Form();
loginDlg.Text = "Login";
loginDlg.Width = 500;
loginDlg.Height = 600;
loginDlg.StartPosition = FormStartPosition.CenterScreen;
WebBrowser browser = new WebBrowser();
browser.Navigate(url);
browser.Dock = DockStyle.Fill;
loginDlg.Controls.Add(browser);
loginDlg.ShowDialog();
m_Auth = m_Flickr.AuthGetToken(frob);
m_Flickr.AuthToken = m_Auth.Token;
}
private void ShowProfile()
{
FlickrNet.FoundUser user = m_Auth.User;
MessageBox.Show(string.Format(
@“FullName: {0} UserId: {1} UserName: {2}”, user.FullName, user.UserId, user.UserName)); }
private void ShowFriends()
{
var form = new Form();
var tooltip = new ToolTip();
var container = new FlowLayoutPanel() { Dock = DockStyle.Fill};
foreach (var contact in m_Flickr.ContactsGetList())
{
var person = m_Flickr.PeopleGetInfo(contact.UserId);
var pic = new PictureBox() { ImageLocation = contact.BuddyIconUrl, SizeMode = PictureBoxSizeMode.AutoSize };
tooltip.SetToolTip(pic, contact.UserName);
container.Controls.Add(pic);
}
form.Controls.Add(container);
form.ShowDialog();
}
private void ShowPhotos(string userID)
{
var form = new Form();
var container = new FlowLayoutPanel() { Dock = DockStyle.Fill };
var photoSets = m_Flickr.PhotosetsGetList(userID);
foreach (var photoSet in photoSets)
{
var pic = new PictureBox() { ImageLocation = photoSet.PhotosetThumbnailUrl, BorderStyle = BorderStyle.FixedSingle, SizeMode = PictureBoxSizeMode.AutoSize };
container.Controls.Add(pic);
}
var photos = m_Flickr.PhotosGetNotInSet();
foreach (var photo in photos)
{
var pic = new PictureBox() { ImageLocation = photo.ThumbnailUrl, SizeMode = PictureBoxSizeMode.AutoSize };
container.Controls.Add(pic);
}
form.Controls.Add(container);
form.ShowDialog();
}
private void ShowInterestingPhotos()
{
ShowPhotoCollection(m_Flickr.InterestingnessGetList());
}
private void ShowPhotoCollection(FlickrNet.PhotoCollection photos)
{
var form = new Form();
var container = new FlowLayoutPanel() { Dock = DockStyle.Fill };
foreach (var photo in photos)
{
var pic = new PictureBox() { ImageLocation = photo.ThumbnailUrl, BorderStyle = BorderStyle.FixedSingle, SizeMode = PictureBoxSizeMode.AutoSize };
container.Controls.Add(pic);
}
form.Controls.Add(container);
form.ShowDialog();
}
#endregion
#region Event Process
private void btnLogin_Click(object sender, EventArgs e)
{
Login();
}
private void btnProfile_Click(object sender, EventArgs e)
{
ShowProfile();
}
private void btnFriends_Click(object sender, EventArgs e)
{
ShowFriends();
}
private void btnMyPhotos_Click(object sender, EventArgs e)
{
ShowPhotos(m_Auth.User.UserId);
}
#endregion
private void btnInteresting_Click(object sender, EventArgs e)
{
ShowInterestingPhotos();
}
}
}