PAWA.Classes.SocialMediaTools.PostToFacebook C# (CSharp) Метод

PostToFacebook() публичный Метод

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
Результат void
        public void PostToFacebook(string ImageName, FacebookClient fbClient)
        {
            //need to find a way to generate one of these badboys for each user
            //accessToken = "574337319304836|b2C4ux1eLIwslioarBVTS6A0Ruo";
            string Extension = checkExtension(ImageName);
            var imgstream = File.OpenRead(System.Web.HttpContext.Current.Server.MapPath("~/Images/User/" + ImageName.Split('.')[0] + Extension));

            dynamic res = fbClient.Post("/me/photos", new
            {
                message = "Uploaded from my PAWA Album.", //Use this to change the images title
                file = new FacebookMediaStream
                {
                    ContentType = ("image/" + Extension.Replace(".","")), //Remove the . from the extension
                    FileName = "TestFileName"
                }.SetValue(imgstream)
            });
        }

Usage Example

Пример #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());
            }
        }