public string UploadToFacebook(MemoryStream ms) { // TODO: Make progressbar functional for C# Facebook SDK. // Limitation in current C# Facebook SDK makes us unable to track progress of photo uploads. this.ProgressBar.Start("Facebook", ms.Length); string url = ""; try { ms.Seek(0, SeekOrigin.Begin); FacebookMediaStream img = new FacebookMediaStream(); img.ContentType = "image/png"; img.FileName = this.RandomFilename(5) + ".png"; img.SetValue(ms); Dictionary <string, object> photoParams = new Dictionary <string, object>(); // TODO: Some way to attach a message to an image //photoParams["message"] = message; photoParams["image"] = img; dynamic ret = this.facebookClient.Post("/me/photos", photoParams); string photoID = ret.id; url = "https://" + "www.facebook.com/photo.php?fbid=" + photoID; this.AddLog(url); } catch (Exception ex) { this.Debug("UploadToFacebook threw " + ex.GetType().FullName + ": '" + ex.Message + "'"); } this.ProgressBar.Done(); return(url); }
public async Task <JsonResult> PostVideo(IEnumerable <HttpPostedFileBase> VideosToUpload, string VideoDescription) { var access_token = HttpContext.Items["access_token"].ToString(); //Get Upload Photo Data var UploadedVideo = VideosToUpload.First(); var video_FBObject = new Facebook.FacebookMediaStream { FileName = UploadedVideo.FileName, ContentType = UploadedVideo.ContentType }; video_FBObject.SetValue(UploadedVideo.InputStream); //FB Graph API Parameters dynamic parameters = new ExpandoObject(); parameters.access_token = access_token; //If you have enabled requires app secret proof on FB app dashboard for your registerted application //parameters.appsecret_proof = access_token.GenerateAppSecretProof(); parameters.source = video_FBObject; if (!string.IsNullOrEmpty(VideoDescription)) { parameters.message = VideoDescription; } //region FB Graph API Add Photo var fb = new FacebookClient(); dynamic result = await fb.PostTaskAsync( "/me/videos", parameters); #region Add Photo Result if (result != null && result.id != null) { if (result.post_id != null) { return(Json(new { status = "posted" })); } else { return(Json(new { status = "pending" })); } } else { return(Json(new { status = "failed" })); } #endregion }
public async Task <JsonResult> PostPhoto(IEnumerable <HttpPostedFileBase> PhotosToUpload, string TargetAlbumId, string PhotoDescription) { var access_token = HttpContext.Items["access_token"].ToString(); if (!string.IsNullOrEmpty(access_token)) { if (PhotosToUpload != null && PhotosToUpload.Count() > 0 && PhotosToUpload.First().HasFile() && !string.IsNullOrEmpty(TargetAlbumId)) { #region Get Upload Photo Data var UploadedPhoto = PhotosToUpload.First(); var photo_FBObject = new Facebook.FacebookMediaStream { FileName = UploadedPhoto.FileName, ContentType = UploadedPhoto.ContentType }; photo_FBObject.SetValue(UploadedPhoto.InputStream); #endregion #region FB Graph API Parameters dynamic parameters = new ExpandoObject(); parameters.access_token = access_token; parameters.appsecret_proof = access_token.GenerateAppSecretProof(); parameters.source = photo_FBObject; if (!string.IsNullOrEmpty(PhotoDescription)) { parameters.message = PhotoDescription; } #endregion #region FB Graph API Add Photo var fb = new FacebookClient(); dynamic result = await fb.PostTaskAsync( string.Format("/{0}/photos", TargetAlbumId), parameters); #endregion #region Add Photo Result if (result != null && result.id != null) { if (result.post_id != null) { return(Json(new { status = "posted" })); } else { return(Json(new { status = "pending" })); } } else { return(Json(new { status = "failed" })); } #endregion } return(null); } else { throw new HttpException(404, "Missing Access Token"); } }
/// <summary> /// Post photo on wall of facebook user /// </summary> public void PostPhoto() { var facebookClient = new FacebookClient(_accessToken); FacebookMediaStream media = new FacebookMediaStream {ContentType = "image/jpeg", FileName = "test Image"}; media.SetValue(_imgStream); facebookClient.PostCompleted += (o, args) => { if (args.Error != null) { Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message)); return; } var result = (IDictionary<string, object>) args.GetResultData(); _lastMessageId = (string) result["id"]; Dispatcher.BeginInvoke(() => { MessageBox.Show( "Message Posted successfully"); btnDeletePost.IsEnabled = true; }); }; IDictionary<string, object> parameters = new Dictionary<string, object>(); //// to upload photo with link //parameters["name"] = "Check this out"; //parameters["link"] = "www.xyz.com"; //parameters["caption"] = "xyz dot com"; //parameters["description"] = "Test url hello how are you, Black Code , Media Test"; //parameters["picture"] = media; //parameters["message"] = "Check this out"; //parameters["actions"] = ""; //facebookClient.PostAsync("me/feed", parameters); // to upload only photo with message parameters["message"] = "Photo upload test " + DateTime.Now.ToString(); parameters["file"] = media; facebookClient.PostAsync("me/Photos", parameters); // post photo on wall }
public string UploadVideoToFacebook(Stream videoStream) { this.ProgressBar.Start("Facebook", videoStream.Length); string url = ""; FacebookMediaStream video = new FacebookMediaStream(); video.ContentType = "video/mp4"; video.FileName = this.RandomFilename(5) + ".mp4"; video.SetValue(videoStream); Dictionary<string, object> videoParams = new Dictionary<string, object>(); videoParams["video"] = video; dynamic ret = this.facebookClient.Post("/me/videos", videoParams); string videoID = ret.id; url = "https://www.facebook.com/video.php?v=" + videoID; this.ProgressBar.Done(); return url; }
public string UploadToFacebook(MemoryStream ms) { // TODO: Make progressbar functional for C# Facebook SDK. // Limitation in current C# Facebook SDK makes us unable to track progress of photo uploads. this.ProgressBar.Start("Facebook", ms.Length); string url = ""; ms.Seek(0, SeekOrigin.Begin); FacebookMediaStream img = new FacebookMediaStream(); img.ContentType = "image/png"; img.FileName = this.RandomFilename(5) + ".png"; img.SetValue(ms); Dictionary<string, object> photoParams = new Dictionary<string, object>(); // TODO: Some way to attach a message to an image //photoParams["message"] = message; photoParams["image"] = img; dynamic ret = this.facebookClient.Post("/me/photos", photoParams); string photoID = ret.id; url = "https://www.facebook.com/photo.php?fbid=" + photoID; this.ProgressBar.Done(); return url; }