PostToFacebook() public method

Posts a image to facebook into the default API album Using the currently open client and imagename for file Note: Token was previously attached to client
public PostToFacebook ( string ImageName, FacebookClient fbClient ) : void
ImageName string
fbClient Facebook.FacebookClient
return void
Esempio n. 1
0
        //
        // GET: /Image/
        public ActionResult DisplayImage(string filename)
        {
            int UserID = WebSecurity.CurrentUserId;

            if (Request.QueryString["code"] != null)
            {
                SocialMediaTools socTools = new SocialMediaTools();
                var fb = new FacebookClient();
                string accessCode = Request.QueryString["code"].ToString();

                dynamic result = fb.Post("oauth/access_token", new
                {
                    client_id = "333143620161224", //This is my facebook APP ID
                    client_secret = "48a7bbdec0e82f32af25681980b288d0", //The APP's SECRET ID
                    redirect_uri = Request.Url.AbsoluteUri.ToString(),
                    code = accessCode //Code used to swap for Token

                });
                //Check result object for the token
                var accessToken = result.access_token;
                //Throw Token into a session, incase we might need later
                Session["AccessToken"] = accessToken;
                //Attach Token to Current Clients token paramater
                fb.AccessToken = accessToken;
                //Start Upload, passing filename and currently open client
                socTools.PostToFacebook(filename, fb);
                //Completed
                Response.Redirect("./../Home/Album");
                return View();
            }
            else
            {
                var files = from f in dbContext.Files
                            where f.UserID == UserID &&
                                  f.Filename == filename
                            select f;

                ViewBag.Tags = PAWA.Classes.DisplayImage.GetTags(dbContext, files.First().Tags);
                int value = files.SingleOrDefault().FileID;
                ViewBag.FolderId = files.SingleOrDefault().FolderID;

                return View(files.First());
            }
        }