本文整理汇总了C#中Facebook.FacebookClient.Post方法的典型用法代码示例。如果您正苦于以下问题:C# FacebookClient.Post方法的具体用法?C# FacebookClient.Post怎么用?C# FacebookClient.Post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook.FacebookClient
的用法示例。
在下文中一共展示了FacebookClient.Post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostScheduleMessage
public override void PostScheduleMessage(dynamic data)
{
try
{
FacebookAccountRepository fbaccrepo = new FacebookAccountRepository();
//IEnumerable<FacebookAccount> lstfbaccount = fbaccrepo.getUserDetails(data.ProfileId);
FacebookAccount fbaccount = fbaccrepo.getUserDetails(data.ProfileId);
//FacebookAccount fbaccount = null;
//foreach (FacebookAccount item in lstfbaccount)
//{
// fbaccount = item;
// break;
//}
FacebookClient fbclient = new FacebookClient(fbaccount.AccessToken);
var args = new Dictionary<string, object>();
args["message"] = data.ShareMessage;
//var facebookpost = fbclient.Post("/me/feed", args);
var facebookpost = "";
if (fbaccount.Type == "page")
{
facebookpost = fbclient.Post("/" + fbaccount.FbUserId + "/feed", args).ToString();
}
else
{
facebookpost = fbclient.Post("/me/feed", args).ToString();
}
Console.WriteLine("Message post on facebook for Id :" + fbaccount.FbUserId + " and Message: " + data.ShareMessage);
ScheduledMessageRepository schrepo = new ScheduledMessageRepository();
ScheduledMessage schmsg = new ScheduledMessage();
schmsg.Id = data.Id;
schmsg.ProfileId = data.ProfileId;
schmsg.ProfileType = "";
schmsg.Status = true;
schmsg.UserId = data.UserId;
schmsg.ShareMessage = data.ShareMessage;
schmsg.ScheduleTime = data.ScheduleTime;
schmsg.ClientTime = data.ClientTime;
schmsg.CreateTime = data.CreateTime;
schmsg.PicUrl = data.PicUrl;
schrepo.updateMessage(data.Id);
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
示例2: FacebookCallback
public ActionResult FacebookCallback(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = System.Configuration.ConfigurationManager.AppSettings["FacebookAppID"],
client_secret = System.Configuration.ConfigurationManager.AppSettings["FacebookAppSecret"],
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});
var accessToken = result.access_token;
fb.AccessToken = accessToken;
dynamic me = fb.Get("me?fields=email");
if (!IsUserRegistered(me.mail))
{
using (TicketBookingEntities db = new TicketBookingEntities())
{
string password = DateTime.Now.ToString();
RegisteredUser user = new Models.RegisteredUser() { Username = me.email, Password = password, Email = me.email };
db.RegisteredUsers.Add(user);
db.Memberships.Add(new Models.Membership() { UserID = user.ID, Role = db.Roles.Single(x => x.ID == 1).Name });
db.SaveChanges();
}
}
FormsAuthentication.SetAuthCookie(me.email, false);
Session["login"] = true;
Session["username"] = me.email;
return RedirectToAction("Index", "Home");
}
示例3: PostToMyWall
public static string PostToMyWall(string accessToken, string message)
{
try
{
var fb = new FacebookClient(accessToken);
var parameters = new Dictionary<string, object>
{
{ "method", "stream.publish" },
{ "message", message }
};
var result = fb.Post(parameters);
var postId = (string)result;
Console.WriteLine("Post Id: {0}", postId);
// Note: This json result is not the orginal json string as returned by Facebook.
Console.WriteLine("Json: {0}", result.ToString());
return postId;
}
catch (FacebookApiException ex)
{
// Note: make sure to handle this exception.
throw;
}
}
示例4: FacebookCallback
public ActionResult FacebookCallback(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["LoginId"],
client_secret = ConfigurationManager.AppSettings["LoginSec"],
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});
var access_token = result.access_token;
if (!string.IsNullOrEmpty(access_token))
{
fb.AccessToken = access_token;
dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email");
string email = me.email;
string username = me.email;
string firstname = me.first_name;
string middlename = me.middle_name;
string lastname = me.last_name;
var kh = new KhachHang();
kh.Email = email;
kh.TenDangNhap = username;
kh.MatKhau = "123";
kh.Ten = lastname + middlename + firstname;
kh.PerId = 1;
kh.SoDienThoai = "";
kh.DiaChi = "";
Session["LogedName"] = username;
var check = khachHang.AddUserForFacebook(kh);
}
return RedirectToAction("Index", "Home");
}
示例5: FacebookCallback
public ActionResult FacebookCallback(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = "1539813469663309",
client_secret = "0883fd6699f9f387a575e12d28391751",
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});
var accessToken = result.access_token;
// Store the access token in the session
Session["AccessToken"] = accessToken;
// update the facebook client with the access token so
// we can make requests on behalf of the user
fb.AccessToken = accessToken;
// Get the user's information
dynamic me = fb.Get("me?fields=first_name,last_name,id,email, friends, likes");
Console.WriteLine(me);
// Set the auth cookie
FormsAuthentication.SetAuthCookie(me.email, false);
return RedirectToAction("Index", "Home");
}
示例6: FacebookCallback
public ActionResult FacebookCallback(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = "100106430186046",
client_secret = "7c9ee3c7e3a1362098ad88b7a9227fc8",
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});
var accessToken = result.access_token;
// Store the access token in the session
Session["AccessToken"] = accessToken;
// update the facebook client with the access token so
// we can make requests on behalf of the user
fb.AccessToken = accessToken;
// Get the user's information
dynamic me = fb.Get("me?fields=first_name,last_name,id,email");
string user = string.Join(" ", me.first_name, me.last_name);
// Set the auth cookie
FormsAuthentication.SetAuthCookie(user, false);
return RedirectToAction("Index", "Home");
}
示例7: Authenticate
public ActionResult Authenticate(String code)
{
FacebookClient client = new FacebookClient();
dynamic temp = client.Post("oauth/access_token", new
{
client_id = "603680269694814",
client_secret = "c45641c9de012c138f1658aa95a6c27d",
redirect_uri = Url.Action("Authenticate", "User", null, Request.Url.Scheme),
code = code
});
client.AccessToken = temp.access_token;
dynamic properties = client.Get("me?fields=first_name,last_name,id,email");
String email = properties.email;
User user = repository.FindBy(u => u.email == email).SingleOrDefault();
if (user == null)
user = CreateNewUser(properties);
FormsAuthentication.SetAuthCookie(user.email, false);
return RedirectToAction("Index", "User");
}
示例8: FacebookCallback
public ActionResult FacebookCallback(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = "887117078046213",
client_secret = "d27adbc1c24cffa0fb4849592a3befd9",
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});
var accessToken = result.access_token;
// Store the access token in the session for farther use
Session["AccessToken"] = accessToken;
// update the facebook client with the access token so
// we can make requests on behalf of the user
fb.AccessToken = accessToken;
// Get the user's information
dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email");
string email = me.email;
string firstname = me.first_name;
string middlename = me.middle_name;
string lastname = me.last_name;
@Session["LogedUserName"] = me.first_name;
@Session["LogedUserLastName"] = me.last_name;
@Session["LogedUserEmail"] = me.email;
// Set the auth cookie
FormsAuthentication.SetAuthCookie(email, false);
return RedirectToAction("CheckExternalLoginRegister", "Login");
}
示例9: Create
public ActionResult Create([Bind(Include = "ID,Title,Writer,WebSite,PostingDate,Content,Image,Video")] Post post, bool ImageCheckBox, bool VideoCheckBox)
{
post.Comments = new List<Comment>();
if (ModelState.IsValid)
{
if (!ImageCheckBox)
post.Image = string.Empty;
if (!VideoCheckBox)
post.Video = string.Empty;
db.Posts.Add(post);
db.SaveChanges();
if (FanClubController.access_token != "")
{
var client = new FacebookClient(FanClubController.access_token);
client.Post("/me/feed/", new { message = string.Format("Title is:{0} And Writer is:{1}", post.Title, post.Writer) });
}
return RedirectToAction("Index");
}
return View(post);
}
示例10: ConnectResponse
public ActionResult ConnectResponse(string state, string code, string error, string error_reason, string error_description, string access_token, string expires)
{
if (string.IsNullOrEmpty(error))
{
try
{
var client = new FacebookClient();
dynamic result = client.Post("oauth/access_token",
new
{
client_id = "435662283157258",
client_secret = "66b1e2c2ba9eed935bce0c8fb4553f28",
redirect_uri = "http://localhost:23232/Home/ConnectResponse",
code = code
});
Session["AccessToken"] = result.access_token;
if (result.ContainsKey("expires"))
Session["ExpiresIn"] = DateTime.Now.AddSeconds(result.expires);
}
catch
{
// handle errors
}
}
else
{
// Declined, check error
}
return RedirectToAction("Main");
}
示例11: DeletePost
public static string DeletePost(string accessToken, string postId)
{
try
{
var fb = new FacebookClient(accessToken);
var parameters = new Dictionary<string, object>
{
{ "method", "stream.remove" },
{ "post_id", postId }
};
var result = fb.Post(parameters);
// Note: This json result is not the orginal json string as returned by Facebook.
Console.WriteLine("Json: {0}", result.ToString());
return postId;
}
catch (FacebookApiException ex)
{
// Note: make sure to handle this exception.
throw;
}
}
示例12: FacebookCallback
public ActionResult FacebookCallback(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = "462931197153588",
client_secret = "82c4ec01d4516d06889341aed8857e5b",
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});
var accessToken = result.access_token;
// Store the access token in the session
Session["AccessToken"] = accessToken;
// update the facebook client with the access token so
// we can make requests on behalf of the user
fb.AccessToken = accessToken;
// Get the user's information
dynamic me = fb.Get("me?fields=first_name,last_name,id,email");
string email = me.email;
// Set the auth cookie
FormsAuthentication.SetAuthCookie(email, false);
return RedirectToAction("Index", "Home");
}
示例13: Send
public void Send()
{
string pageID = "PPIJ2012";
facebookClient = new FacebookClient(facebookData.Token);
facebookClient.Post(pageID + "/feed", new { message = facebookData.Message });
}
示例14: btnPostToWall_Click
protected void btnPostToWall_Click(object sender, EventArgs e)
{
FacebookClient fbClient = new FacebookClient(fb_token);
var args = new Dictionary<string, object>();
args["message"] = "Testing 123";
fbClient.Post("/me/feed", args);
lblPostSuccess.Text = "successfully posted";
}
示例15: CheckAuthorization
public void CheckAuthorization()
{
const string appId = "491313520953187";
const string appSecret = "3d057585b000c1b1830b9de8ec7fb8f5";
const string scope = "publish_stream,manage_pages";
if (HttpContext.Current.Request["code"] == null)
{
HttpContext.Current.Response.Redirect(string.Format(
"https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
appId, HttpContext.Current.Request.Url.AbsoluteUri, scope));
}
else
{
var tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
appId, HttpContext.Current.Request.Url.AbsoluteUri, scope, HttpContext.Current.Request["code"], appSecret);
var request = WebRequest.Create(url) as HttpWebRequest;
if (request != null)
using (var response = request.GetResponse() as HttpWebResponse)
{
if (response != null)
{
var reader = new StreamReader(response.GetResponseStream());
var vals = reader.ReadToEnd();
foreach (string token in vals.Split('&'))
{
//meh.aspx?token1=steve&token2=jake&...
tokens.Add(token.Substring(0, token.IndexOf("=", StringComparison.Ordinal)),
token.Substring(token.IndexOf("=", StringComparison.Ordinal) + 1, token.Length - token.IndexOf("=", StringComparison.Ordinal) - 1));
}
}
}
var accessToken = tokens["access_token"];
var client = new FacebookClient(accessToken);
client.Post("/me/feed", new { message = "test 101" });
}
}