.Net Facebook Developer Toolkit – 讀取自己 Facebook Account 上 指定一個 Photo Album 既 Photo List
Reference 要 Import 上 "C:\Program Files\Coding4Fun\Facebook\Binaries" 既 "Facebook.WebControls.dll" / "Facebook.dll"
WebForm6.aspx |
… … <asp:Literal ID="Literal1" runat="server"></asp:Literal> … … |
WebForm6.aspx.cs |
using System; using Facebook; using Facebook.WebControls; namespace WebApplication12 { public partial class WebForm6 : System.Web.UI.Page { Facebook.Components.FacebookService FBService = new Facebook.Components.FacebookService(); protected void Page_Load(object sender, EventArgs e) { CheckLogin(); if (!IsPostBack){ GetPhotoAlbum("<Album Name>"); } } private void GetPhotoAlbum(String input) { String aid = GetAlbumID(input); if (aid != "" && FBService.GetPhotos(aid) != null && FBService.GetPhotos(aid).Count > 0){ int i = 0; Literal1.Text += "<table border='0' cellpadding='3' cellspacing='0'>"; foreach (Facebook.Photo photo in FBService.GetPhotos(aid)){ if ((i % 6) == 0){ Literal1.Text += "<tr>\n"; } Literal1.Text += "<td>\n"; Literal1.Text += "<a href='" + photo.Link.ToString() + "' style='outline:none;'>\n"; Literal1.Text += "<img border='0' src='" + photo.PictureUrl.ToString() + "'>\n"; Literal1.Text += "</a></td>\n"; if ((i % 6) == 5){ Literal1.Text += "</tr>\n"; } i++; } Literal1.Text += "</table>"; }else{ Literal1.Text = "null<br/>"; } } private String GetAlbumID(String input) { String result = ""; foreach (Facebook.Album album in FBService.GetPhotoAlbums()){ if (album.Name.Trim() == input) result = album.AlbumId; } if (result != "") return result; else return ""; } private void CheckLogin() { FBService.ApplicationKey = "<應用程式 ID/API 鑰匙>"; FBService.Secret = "<應用程式密鑰>"; FBService.IsDesktopApplication = false; string sessionKey = Session["Facebook_session_key"] as String; string userId = Session["Facebook_userId"] as String; string authToken = Request.QueryString["auth_token"]; if (!String.IsNullOrEmpty(sessionKey)){ FBService.SessionKey = sessionKey; FBService.UserId = userId; }else if (!String.IsNullOrEmpty(authToken)){ FBService.CreateSession(authToken); Session["Facebook_session_key"] = FBService.SessionKey; Session["Facebook_userId"] = FBService.UserId; Session["Facebook_session_expires"] = FBService.SessionExpires; }else{ Response.Redirect(@"http://www.Facebook.com/login.php?api_key=" + FBService.ApplicationKey + @"&v=1.0"); } } } } |