本文整理汇总了C#中Facebook.FacebookClient.PostAsync方法的典型用法代码示例。如果您正苦于以下问题:C# FacebookClient.PostAsync方法的具体用法?C# FacebookClient.PostAsync怎么用?C# FacebookClient.PostAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook.FacebookClient
的用法示例。
在下文中一共展示了FacebookClient.PostAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnUpload_Click
private void btnUpload_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(_filename))
{
MessageBox.Show("Please select the image file first.");
return;
}
var mediaObject = new FacebookMediaObject
{
ContentType = "image/jpeg",
FileName = Path.GetFileName(_filename)
}
.SetValue(File.ReadAllBytes(_filename));
progressBar1.Value = 0;
var fb = new FacebookClient(_accessToken);
fb.UploadProgressChanged += fb_UploadProgressChanged;
fb.PostCompleted += fb_PostCompleted;
// for cancellation
_fb = fb;
fb.PostAsync("/me/photos", new Dictionary<string, object> { { "source", mediaObject } });
}
示例2: CreateEvent
/// <summary>
///
/// </summary>
/// <param name="name">Name of event</param>
/// <param name="description">Description</param>
/// <param name="startTime">Start Time, UNIX format= 2012-06-14T12:22:23</param>
/// <param name="endTime">End Time, not needde</param>
/// <param name="location">Location</param>
/// <param name="privacy">Privacy type</param>
public void CreateEvent(string name, string description, string startTime, string endTime, string location, EventPrivacy privacy)
{
RFBClient = new FacebookClient(FBAuthenticationService.AccessToken);
RFBClient.PostCompleted += new EventHandler<FacebookApiEventArgs>(RFBClient_PostCompleted);
RFBClient.PostAsync(FetchString, new
{
name = name,
start_time = startTime,
end_time = endTime,
description = description,
location = location,
privacy_type = privacyToString(privacy)
});
}
示例3: Upload
void Upload(bool fUsingSavedAccessToken)
{
FacebookClient fb = new FacebookClient(this.accessToken);
// make sure to add event handler for PostCompleted.
fb.PostCompleted += (o, e) =>
{
if (e.Error != null)
{
if (fUsingSavedAccessToken && e.Error is Facebook.FacebookOAuthException)
{
//the access token is invalid (maybe expired)
//Application.Current.Dispatcher.BeginInvoke(new Action(() =>
// {
// Config.FacebookAccessToken = null;
// this.AuthAndUpload(filePath);
// }
//));
App.Instance.BeginInvoke(new Action(() =>
{
Config.FacebookAccessToken = null;
this.AuthAndUpload(filePath);
}
));
}
else
{
App.Instance.AddError(Config.FACEBOOK_ERROR, Config.FACEBOOK_TITLE);
}
}
else
{
App.Instance.AddMessage(Config.FACEBOOK_SUCCEED, Config.FACEBOOK_TITLE);
}
};
var photoDetail = new Dictionary<string, object>();
photoDetail.Add("message", message);
photoDetail.Add("source", new FacebookMediaObject
{
ContentType = "image/png",
FileName = filePath
}.SetValue(File.ReadAllBytes(filePath)));
fb.PostAsync("me/photos", photoDetail);
//dynamic parameters = new ExpandoObject();
//parameters.message = "Posted from Clipoff";
//parameters.source = new FacebookMediaObject
//{
// ContentType = "image/png",
// FileName = filePath
//}.SetValue(File.ReadAllBytes(filePath));
//fb.PostAsync("me/photos", parameters);
}
示例4: SetRsvp
public void SetRsvp(string name, ActivityItemsViewModel act)
{
if (App.ViewModel.UserPreference.AccessKey == null || act.FacebookId == null || act.FacebookId.Equals("") || !App.ViewModel.HasConnection)
return;
var fb = new FacebookClient { AccessToken = App.ViewModel.UserPreference.AccessKey, AppId = App.ViewModel.Appid };
fb.GetCompleted += (o, e) =>
{
if (e.Error != null)
{
Deployment.Current.Dispatcher.BeginInvoke(
() => MessageBox.Show(
"Er gebeurde een fout tijdens het versturen van data naar Facebook"));
}
act.RsvpStatus = GetRsvp(act).ToString();
};
var query = string.Format("https://graph.facebook.com/{0}/{1}", act.FacebookId, name);
fb.PostAsync(query, null);
}
示例5: ShareOnFacebook
public void ShareOnFacebook()
{
string post = "";
post = "";
if (ffid == " " && fftoken == " " || ffid == null && fftoken == null)
{
NavigationService.Navigate(new Uri(string.Format("/FacebookLoginPage.xaml?vpost={0}", post), UriKind.Relative));
}
else
{
var fb = new FacebookClient(fftoken);
fb.PostCompleted += (o, e) =>
{
if (e.Cancelled || e.Error != null)
{
Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
return;
}
var result = e.GetResultData();
Dispatcher.BeginInvoke(() =>
{
progbar1.IsIndeterminate = false;
progbar1.Visibility = Visibility.Collapsed;
// MessageBox.Show("Successfully shared on Facebook");
//if (NavigationService.CanGoBack)
// NavigationService.GoBack();
buyNowScreen = new Popup();
buyNowScreen.Child =
new NotifyAlert
("Successfully shared on Facebook");
buyNowScreen.IsOpen = true;
buyNowScreen.VerticalOffset = 0;
buyNowScreen.HorizontalOffset = 0;
});
};
//IsolatedSettingsHelper.SetValue<bool>("sharedonfacebook", true);
//Dispatcher.BeginInvoke(() =>
//{
// buyNowScreen = new Popup();
// buyNowScreen.Child =
// new NotifyAlert
// ("Successfully shared on Facebook");
// buyNowScreen.IsOpen = true;
// buyNowScreen.VerticalOffset = 0;
// buyNowScreen.HorizontalOffset = 0;
//});
var parameters = new Dictionary<string, object>();
parameters["name"] = photo_text.Text;
var resized = img.Resize(img.PixelWidth / 2, img.PixelHeight / 2, WriteableBitmapExtensions.Interpolation.Bilinear);
var fileStream = new MemoryStream();
resized.SaveJpeg(fileStream, resized.PixelWidth, resized.PixelHeight, 100, 100);
fileStream.Seek(0, SeekOrigin.Begin);
parameters["TestPic"] = new FacebookMediaObject
{
ContentType = "image/jpeg",
FileName = fileName + ".jpg"
}.SetValue(fileStream.ToArray());//.SetValue(photoStream.ToArray());
//fb.PostCompleted += fb_PostCompleted;
fb.PostAsync("me/Photos", parameters);
string channel = IsolatedSettingsHelper.GetValue<string>("latest_update_channel");
IsolatedSettingsHelper.SetValue<string>("latest_update", "You shared a photo");
IsolatedSettingsHelper.SetValue<string>("latest_update_channel", channel + " Facebook");
IsolatedSettingsHelper.SetValue<string>("latest_update_time", DateTime.Now.ToString());
}
}
示例6: WallPost
/// <summary>
/// Post on wall of Facebook user
/// </summary>
public void WallPost()
{
var fb = new FacebookClient(_accessToken);
fb.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");
txtAnswer.Text = string.Empty;
btnDeletePost.IsEnabled = true;
});
};
var parameters = new Dictionary<string, object>();
parameters["message"] = txtInput.Text;
fb.PostAsync("me/feed", parameters); // post message on wall of user
}
示例7: CheckIn
/// <summary>
/// Checkin current location of user on facebook
/// </summary>
public void CheckIn()
{
var fb = new FacebookClient(_accessToken);
fb.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"]; // get result id of post
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Checkin done successfully");
});
};
var parameters = new Dictionary<string, object>();
//parameters["message"] = txtInput.Text;
parameters["place"] = "173205796066382"; // place of check in
parameters["coordinates"] = "28.627116663763,77.375440942471"; // coordinates of checkin
// post for checkin
fb.PostAsync("me/feed", parameters);
}
示例8: Publicar
private void Publicar(string arg1, string name, string time, string message = "")
{
try
{
string test = GetPageAccessToken(_accessToken);
var Variab = new Variables();
var fb = new FacebookClient(test);
// make sure to add event handler for PostCompleted.
fb.PostCompleted += (o, e) =>
{
// incase you support cancellation, make sure to check
// e.Cancelled property first even before checking (e.Error!=null).
if (e.Cancelled)
{
// for this example, we can ignore as we don't allow this
// example to be cancelled.
// you can check e.Error for reasons behind the cancellation.
var cancellationError = e.Error;
}
else if (e.Error != null)
{
// error occurred
this.BeginInvoke(new MethodInvoker(
() =>
{
//MessageBox.Show(e.Error.Message);
}));
}
else
{
// the request was completed successfully
// now we can either cast it to IDictionary<string, object> or IList<object>
// depending on the type. or we could use dynamic.
dynamic result = e.GetResultData();
_lastMessageId = result.id;
// make sure to be on the right thread when working with ui.
this.BeginInvoke(new MethodInvoker(
() =>
{
//MessageBox.Show("Message Posted successfully");
//txtMessage.Text = string.Empty;
//btnDeleteLastMessage.Enabled = true;
}));
}
};
dynamic parameters = new ExpandoObject();
parameters.privacy = new
{
value = "ALL_FRIENDS",
};
parameters.name = name;
parameters.message = message;
if (arg1.Contains("/wow/en/item/") == true)
{
parameters.link = "http://us.battle.net" + arg1;
}
else
{
parameters.link = "http://us.battle.net/" + arg1;
}
//parameters.link = "http://us.battle.net/wow/en/character/quelthalas/Amadoflimd/" + arg1;
//s.ResponseUri.AbsoluteUri
parameters.caption = "Realm: " + Variables.Realm;
fb.PostAsync("/" + Variables.PageID + "/feed", parameters);
StreamWriter sw = new StreamWriter("C:\\UpdatesGuild.txt", true);
//Write a line of text
sw.WriteLine(name);
//sw.WriteLine(Environment.NewLine);
//sw.Flush();
//Close the file
sw.Close();
}
catch (Exception ex)
{
}
}
示例9: PostToWall
public static void PostToWall(string msg)
{
if (wasLoginCancelled == true)
Login();
if (LoggedIn != true)
throw new Exception("User is not logged in!");
var fb = new FacebookClient(AccessToken);
// make sure to add event handler for PostCompleted.
fb.PostCompleted += (o, e) =>
{
// incase you support cancellation, make sure to check
// e.Cancelled property first even before checking (e.Error!=null).
if (e.Cancelled)
{
// for this example, we can ignore as we don't allow this
// example to be cancelled.
// you can check e.Error for reasons behind the cancellation.
throw e.Error;
}
else if (e.Error != null)
{
// error occurred
throw e.Error;
}
else
{
// the request was completed successfully
// now we can either cast it to IDictionary<string, object> or IList<object>
// depending on the type. or we could use dynamic.
dynamic result = e.GetResultData();
//_lastMessageId = result.id;
}
};
dynamic parameters = new ExpandoObject();
parameters.message = msg;
fb.PostAsync("me/feed", parameters);
}
示例10: button3_Click
private void button3_Click(object sender, RibbonControlEventArgs e)
{
if (ThisAddIn.GetAccessToken() == "")
{
MessageBox.Show("請先登入!", "Facebook", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
string select = "";
try
{
PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
var Sld = myPPT.ActiveWindow.View.Slide;
select = myPPT.ActiveWindow.Selection.TextRange.Text;
}
catch (Exception ex)
{
MessageBox.Show("請選取文字!", "Facebook", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
if (select != "")
{
FacebookClient facebook = new FacebookClient(ThisAddIn.GetAccessToken()); // 使用 Token 建立一個 FacebookClient
var parameters = new Dictionary<String, Object>();
facebook.PostCompleted += OnFacebookPostCompleted;
DateTime dt = DateTime.Now;
parameters["message"] = select;
facebook.PostAsync("me/feed", parameters);
}
else
{
MessageBox.Show("請選取文字!", "Facebook", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
示例11: btnPostToWall_Click
private void btnPostToWall_Click(object sender, EventArgs args)
{
var fb = new FacebookClient(_accessToken);
// make sure to add event handler for PostCompleted.
fb.PostCompleted += (o, e) =>
{
// incase you support cancellation, make sure to check
// e.Cancelled property first even before checking (e.Error!=null).
if (e.Cancelled)
{
// for this example, we can ignore as we don't allow this
// example to be cancelled.
// you can check e.Error for reasons behind the cancellation.
var cancellationError = e.Error;
}
else if (e.Error != null)
{
// error occurred
this.BeginInvoke(new MethodInvoker(
() =>
{
MessageBox.Show(e.Error.Message);
}));
}
else
{
// the request was completed successfully
// now we can either cast it to IDictionary<string, object> or IList<object>
// depending on the type. or we could use dynamic.
dynamic result = e.GetResultData();
_lastMessageId = result.id;
// make sure to be on the right thread when working with ui.
this.BeginInvoke(new MethodInvoker(
() =>
{
MessageBox.Show("Message Posted successfully");
txtMessage.Text = string.Empty;
btnDeleteLastMessage.Enabled = true;
}));
}
};
dynamic parameters = new ExpandoObject();
parameters.message = txtMessage.Text;
fb.PostAsync("me/feed", parameters);
}
示例12: postMessage
private void postMessage()
{
if (this.currentWord == null)
{
MessageBox.Show("Enter message.");
return;
}
var fb = new FacebookClient(_accessToken);
fb.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(AppResources.thankYou);
});
};
var parameters = new Dictionary<string, object>();
//parameters["message"] = this.currentOffer.Title;
parameters["name"] = this.currentWord.WordContent;
parameters["caption"] = this.currentWord.Description;
parameters["description"] = this.currentWord.Example;
parameters["link"] = "http://www.neolog.bg/word/" + this.currentWord.WordId;
fb.PostAsync("me/feed", parameters);
Dispatcher.BeginInvoke(() =>
{
NavigationService.GoBack();
});
}
示例13: LoginSucceded
private void LoginSucceded(string accessToken)
{
var fb = new FacebookClient(accessToken);
fb.GetCompleted += (o, e) =>
{
if (e.Error != null)
{
Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
return;
}
var result = (IDictionary<string, object>)e.GetResultData();
var id = (string)result["id"];
IsolatedSettingsHelper.SetValue<string>("ftoken_sharetoall", accessToken);
IsolatedSettingsHelper.SetValue<string>("fid_sharetoall", id);
// string _post = NavigationContext.QueryString["vpost"];
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Successfully shared on Facebook");
});
if (_post.Contains('|'))
{
string[] words = _post.Split('|');
var parameters = new Dictionary<string, object>();
//parameters["message"] = txtMessage.Text;
parameters["message"] = words[0];
parameters["link"] = words[1];
//parameters["picture"] = "";
fb.PostAsync("me/feed", parameters);
}
else
{
var parameters = new Dictionary<string, object>();
//parameters["message"] = txtMessage.Text;
parameters["message"] = _post;
// parameters["link"] = words[1];
//parameters["picture"] = "";
fb.PostAsync("me/feed", parameters);
}
//////////
};
fb.GetAsync("me?fields=id");
}
示例14: webBrowser1_Navigated
private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
// whenever the browser navigates to a new url, try parsing the url
// the url may be the result of OAuth 2.0 authentication.
FacebookOAuthResult oauthResult;
var fb = new FacebookClient();
if (fb.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
{
// The url is the result of OAuth 2.0 authentication.
if (oauthResult.IsSuccess)
{
// we got the code here
fb.PostCompleted+=
(o, args) =>
{
// make sure to check that no error has occurred.
if (args.Error != null)
{
// make sure to access ui stuffs on the correct thread.
Dispatcher.BeginInvoke(
() =>
{
MessageBox.Show(args.Error.Message);
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
});
}
else
{
var result = (IDictionary<string, object>)args.GetResultData();
var accessToken = (string)result["access_token"];
// make sure to access ui stuffs on the correct thread.
Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/FacebookInfoPage.xaml?access_token=" + accessToken, UriKind.Relative)));
}
};
fb.PostAsync("oauth/access_token",new
{
client_id = AppId,
client_secret = AppSecret,
redirect_uri = RedirectUri,
code = oauthResult.Code
});
}
else
{
// the user clicked don't allow or some other error occurred.
MessageBox.Show(oauthResult.ErrorDescription);
}
}
else
{
// The url is NOT the result of OAuth 2.0 authentication.
}
}
示例15: ShareOnFacebook
public void ShareOnFacebook()
{
//ShowProgressIndicator(AppResources.GettingLocationProgressText);
string post = "";
post = update_text.Text;
if (ffid == " " && fftoken == " " || ffid == null && fftoken == null)
{
NavigationService.Navigate(new Uri(string.Format("/FacebookLoginPage.xaml?vpost={0}", post), UriKind.Relative));
}
else
{
var fb = new FacebookClient(fftoken);
fb.PostCompleted += (o, args) =>
{
if (args.Error != null)
{
if (args.Error.Message == "(OAuthException - #506) (#506) Duplicate status message")
{
Dispatcher.BeginInvoke(() => MessageBox.Show("You have already shared it!"));
return;
}
else
{
Dispatcher.BeginInvoke(() => MessageBox.Show(args.Error.Message));
return;
}
}
var result = (IDictionary<string, object>)args.GetResultData();
_lastMessageId = (string)result["id"];
string channel= IsolatedSettingsHelper.GetValue<string>("latest_update_channel");
IsolatedSettingsHelper.SetValue<string>("latest_update", post);
IsolatedSettingsHelper.SetValue<string>("latest_update_channel", channel +" Facebook");
IsolatedSettingsHelper.SetValue<string>("latest_update_time", DateTime.Now.ToString());
//Dispatcher.BeginInvoke(() =>
//{
// // MessageBox.Show("Successfully shared on Facebook");
//});
Dispatcher.BeginInvoke(() =>
{
buyNowScreen1 = new Popup();
buyNowScreen1.Child =
new NotifyAlert
("Successfully shared on Facebook");
buyNowScreen1.IsOpen = true;
buyNowScreen1.VerticalOffset = 0;
buyNowScreen1.HorizontalOffset = 0;
});
//IsolatedSettingsHelper.SetValue<bool>("sharedonfacebook", true);
};
// string[] words = post.Split('|');
var parameters = new Dictionary<string, object>();
//parameters["message"] = txtMessage.Text;
parameters["message"] = post;
//parameters["link"] = words[1];
//parameters["picture"] = "";
fb.PostAsync("me/feed", parameters);
progbar.IsIndeterminate = false;
progbar.Visibility = Visibility.Collapsed;
// HideProgressIndicator();
}
}