.Net Facebook Developer Toolkit – 讀取自己 Facebook Account 上 指定堵加 Photo Album 及 Upload Photo
Reference 要 Import 上 "C:\Program Files\Coding4Fun\Facebook\Binaries" 既 "Facebook.WebControls.dll" / "Facebook.dll"
WebForm6.aspx.cs |
using System; using Facebook; using Facebook.WebControls; using System.IO; 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){ FBService.CreateAlbum("XC", "Hong Kong", "Description 1"); FBService.UploadPhoto(GetAlbumID("XC"), new FileInfo(@"C:\XC.png")); } } 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"); } } } } |