如何使用ASP.net 2008从Facebook api 3.0发布消息? [英] how can i post message from facebook api 3.0 with ASP.net 2008?
本文介绍了如何使用ASP.net 2008从Facebook api 3.0发布消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用facebook api wnt将消息发布给其他人
可以吗
问候
Chetan Chaudhari
using facebook api wnt to post messages to other one
Is it posible
Regards
Chetan Chaudhari
推荐答案
尝试在此处查看:
Facebook强大的API [ ^ ]
.NET Facebook API客户端 [ ^ ]
Try to look here:
Facebook''s powerful APIs [^]
.NET Facebook API Client [^]
使用系统;
使用System.Configuration;
使用System.Data;
使用System.Linq;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Xml.Linq;
使用Facebook;
使用Facebook.Web;
使用Facebook.Rest;
使用Facebook.Schema;
使用Facebook.Utility;
使用Facebook.Winforms;
使用Facebook.Session;
使用System.Collections.Generic;
使用Facebook.Winforms.Components;
使用System.Web.UI.MobileControls;
使用System.Net;
使用System.IO;
使用System.Text;
命名空间FacebookDemo
{
公共局部类索引:System.Web.UI.Page
{
//K.Durga Nageswara Rao ..............//
私有常量字符串APPID =您的应用ID";
private const string APPKEY =您的应用程序密钥"; //从Facebook应用程序页面
private const string SECRET =您的应用程序创建";
////Facebook.Web.FbmlControls.PromptPermission提示器=新的Facebook.Web.FbmlControls.PromptPermission();
//Facebook.Session.ConnectSession会话=新的Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey,ConnectAuthentication.SecretKey);
//受保护的无效Page_Load(对象发送者,EventArgs e)
//{
//string sessionKey = Session ["facebook_session_key"] as String;
//string userId = Session ["facebook_userId"]作为字符串;
//string authToken = Request.QueryString ["auth_token"];
//string accesstoken = Request.QueryString ["code"];
//if(!String.IsNullOrEmpty(sessionKey))
//{
//session.SessionKey = sessionKey;
////session.UserId = userId;
//}
//否则((String.IsNullOrEmpty(authToken))
//{
//Session ["facebook_session_key"] = session.SessionKey;
//Session ["facebook_userId"] = session.UserId;
//Session ["facebook_session_expires"] = session.SessionExpires;
//}
//else
//{
//Response.Redirect(@"http://www.facebook.com/login.php?api_key=" + APPKEY + @& v = 1.0");
//}
//如果(ConnectAuthentication.isConnected())
//{
////Facebook.Session.ConnectSession会话=新的Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey,ConnectAuthentication.SecretKey);
//字符串sessionkey = session.SessionKey;
//字符串UserId = session.UserId.ToString();
////session.UserId = ConnectAuthentication.UserID;
//Facebook.Rest.Api api =新的Facebook.Rest.Api(会话);
////显示从Facebook API捕获的用户数据.
//Facebook.Schema.user用户= api.Users.GetInfo();
//字符串fullName = user.first_name +" + user.last_name;
//Panel1.Visible = true;
//Label1.Text = fullName;
//}
//else
//{
////Facebook Connect未通过身份验证,请照常进行.
//}
Facebook.Web.FbmlControls.PromptPermission提示器=新的Facebook.Web.FbmlControls.PromptPermission();
受保护的void Page_Load(对象发送者,EventArgs e)
{
字符串authToken = Request.QueryString ["auth_token"];
如果(ConnectAuthentication.isConnected())
{
Facebook.Session.ConnectSession会话=新的Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey,ConnectAuthentication.SecretKey);
//session.UserId = ConnectAuthentication.UserID;
Facebook.Rest.Api api =新的Facebook.Rest.Api(会话);
//显示从Facebook API捕获的用户数据.
Facebook.Schema.user用户= api.Users.GetInfo();
字符串fullName = user.first_name +" + user.last_name;
Panel1.Visible = true;
Label1.Text = fullName;
Facebook.Schema.pages_getInfo_response pageinfo = new pages_getInfo_response();
System.Web.HttpContext.Current.Session ["sessionkey"] = session.SessionKey;
System.Web.HttpContext.Current.Session ["UserId"] = session.UserId;
System.Web.HttpContext.Current.Session ["AccessToken"] = session.SessionSecret;
//var val = HttpContext.Current.Request.Cookies ["b90e89f2fcf265f26708476a186b1222_user"].Values;//100002386562731
//var val0 = HttpContext.Current.Request.Cookies ["b90e89f2fcf265f26708476a186b1222"].值;//4febeb45d23f49fa9d793c29da703336
//var val1 = HttpContext.Current.Request.Cookies ["b90e89f2fcf265f26708476a186b1222_ss"].Values;//AQA9rwe7RanXzDeV
//var val2 = HttpContext.Current.Request.Cookies ["b90e89f2fcf265f26708476a186b1222_session_key"].Values;//2.AQD709Yz-kp5xWcg.3600.1306418400.1-100002386562731
//var val3 = HttpContext.Current.Request.Cookies ["b90e89f2fcf265f26708476a186b1222_expires"].Values;//1306418400
}
其他
{
if(string.IsNullOrEmpty(ConnectAuthentication.SessionKey))
{
//Page_Load(sender,e);
}
//Response.Redirect(@"http://www.facebook.com/login.php?api_key=" + APPKEY + @& v = 1.0");
}
//postToWall();
//stringsignedRequest = Request.Form ["signed_request"];
//var DecodedSignedRequest = FacebookSignedRequest.Parse(FacebookContext.Current.AppSecret,SignedRequest);
//动态SignedRequestData = DecodedSignedRequest.Data;
//var RawRequestData =(IDictionary< string,object>)SignedRequestData;
//if(RawRequestData.ContainsKey("page")== true)
//{Facebook.JsonObject RawPageData =(Facebook.JsonObject)RawRequestData ["page"];
//如果((RawPageData.ContainsKey("id")== true)
//currentFacebookPageID =(string)RawPageData ["id"];
//}
}
受保护的void Button1_Click(对象发送者,EventArgs e)
{
Facebook.Session.ConnectSession session1 =新的Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey,ConnectAuthentication.SecretKey);
如果(ConnectAuthentication.isConnected())
{
//ConnectAuthentication.UserID = System.Web.HttpContext.Current.Session ["UserId"];
FacebookService fbService =新的FacebookService();
//fbService.SessionKey = session1.SessionKey;
fbService.uid = session1.UserId;
//fbService.ApplicationKey = ConnectAuthentication.ApiKey;
附件attach =新的attachment();
//attach.caption =检查出来...";
//attach.description =从我的Facebook开发应用程序中发布";
//attach.href ="http://www.kennetham.com/";
//attach.name =通过FacebookAPI附加我的Web链接";
attachment_media attach_media =新的attachment_media();
attach_media.type =附件_media_type.image;
attachment_media_image图片=新的attach_media_image();
image.type = attachment_media_type.image;
image.href ="http://profile.ak.fbcdn.net/static-ak/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif";
image.src ="http://profile.ak.fbcdn.net/static-ak/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif";
列表< attachment_media> attach_media_list =新列表< attachment_media>();
attach_media_list.Add(image);
attach.media = attach_media_list;
//attachment_property attach_prop = new attachment_property();
///*动作链接*/
//List< action_link> actionlink =新列表< action_link>();
//action_link al1 = new action_link();
//al1.href ="http://www.kennetham.com/";
//al1.text =肯尼斯·汉姆";
//actionlink.Add(al1);
Facebook.Session.ConnectSession会话=新的Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey,ConnectAuthentication.SecretKey);
//session.UserId = ConnectAuthentication.UserID;
Facebook.Rest.Api api =新的Facebook.Rest.Api(会话);
//显示从Facebook API捕获的用户数据.
字符串publishAccess = api.ExtendedPermissionUrl(Facebook.Schema.Enums.ExtendedPermissions.publish_stream);
Uri uri =新的Uri(String.Format("https://graph.facebook.com/189415601106529/feed?api_key= {0}& v = 1.0& ext_perm = {1}& message = uuuuhhhuuu ... & method = post,ConnectAuthentication.ApiKey,publishAccess)));
Response.Redirect(uri.ToString());
//api.Stream.Publish(TextBox1.Text,attach,actionlink,fbService.uid.ToString(),0);
api.Stream.Publish(TextBox1.Text,null,null,fbService.uid.ToString(),0);
}
其他
{
//Facebook Connect未通过身份验证,请照常进行.
}
}
私有静态Uri GetExtendedPermissionUrl(Enums.ExtendedPermissions权限)
{
返回新的Uri(String.Format("http://www.facebook.com/authorize.php?api_key={0}&v=1.0&ext_perm={1}",ConnectAuthentication.ApiKey,权限));
//返回新的Uri(String.Format("https://graph.facebook.com/189415601106529/feed?api_key= {0}& v = 1.0& ext_perm = {1}& message = uuuuhhhuuu ... & method = post",ConnectAuthentication.ApiKey,权限));
//https://graph.facebook.com/< Page_ID>/feed?access_token =< PAGE_ACCESS_TOKEN_TAKEN_FROM_STEP2>& message = uuuuhhhuuu ...
}
受保护的void Button2_Click(对象发送者,EventArgs e)
{
Enums.ExtendedPermissions perm;
烫发= Enums.ExtendedPermissions.publish_stream;
Uri uri = GetExtendedPermissionUrl(perm);
Response.Redirect(uri.ToString());
}
受保护的void Button3_Click(对象发送者,EventArgs e)
{
//Facebook.Session.ConnectSession session1 =新的Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey,ConnectAuthentication.SecretKey);
//this.Session.Remove("USER_ID);
//this.Session.Remove("FACEBOOK_USER_INFO);
//尝试
//{
//如果(ConnectAuthentication.SessionKey!= null)
//{
//如果(ConnectAuthentication.isConnected())
//{
//this.Session.Clear();
//}//如果if
结束 //}//如果if
结束 //}
//catch(异常前)
//{
//}//结束捕获
//this.Response.Redirect("~/index.aspx,true);
//将消息发布到粉丝页面...........
//动态messagePost = new ExpandoObject();
//messagePost.access_token ="[YOUR_ACCESS_TOKEN]";
//messagePost.picture ="[A_PICTURE]";
//messagePost.link ="[SOME_LINK]"; messagePost.name ="[SOME_NAME]";
//messagePost.caption ="{* actor *}" +"[YOUR_MESSAGE]";
////< --- {* actor *}是用户(即Aaron)
//messagePost.description ="[SOME_DESCRIPTION]";
//FacebookClient应用=新的FacebookClient("[YOUR_ACCESS_TOKEN]");
//尝试{
//var result = app.Post("/" + [PAGE_ID] +"/feed",messagePost);
//}抓到(FacebookOAuthException ex)
//{
////处理一些东西
//}
}
私有IList< page> GetInfo(List< string>字段,List< long> page_ids,long?uid,bool isAsync,Facebook.Rest.Pages.GetInfoCallback回调,对象状态)
{
var parameterList = new Dictionary< string,string> {{"method","facebook.pages.getInfo"}};
Utilities.AddList(parameterList,"fields",fields);
Utilities.AddList(parameterList,"page_ids",page_ids);
Utilities.AddOptionalParameter(parameterList,"uid",uid);
parameterList ["fields"] = parameterList ["fields"].Replace(",");
如果(isAsync)
{
SendRequestAsync< pages_getInfo_response,IList< page>(参数列表,!string.IsNullOrEmpty(System.Web.HttpContext.Current.Session ["sessionkey"].ToString()),新的FacebookCallCompleted< IList< page>>(回调) ,状态,页面");
返回null;
}
var response = SendRequest< pages_getInfo_response>(parameterList,!string.IsNullOrEmpty(System.Web.HttpContext.Current.Session ["sessionkey"].ToString()));
//返回响应== null? null:response.page;
返回null;
}
私有对象SendRequest< T1>(字典< string,string> parameterList,bool p)
{
抛出新的NotImplementedException();
}
私有无效的SendRequestAsync< T1,T2>(字典< string,string> parameterList,bool p,FacebookCallCompleted< IList< page>> facebookCallCompleted,对象状态,字符串p_5)
{
抛出新的NotImplementedException();
}
受保护的void Button3_Click1(对象发送者,EventArgs e)
{
//var dicParams = new Dictionary< string,object>();
//dicParams ["message"] =你好";
//dicParams ["caption"] = string.Empty;
//dicParams ["description"] = string.Empty;
//dicParams ["name"] =样本粉丝页面消息";
//dicParams ["req_perms"] ="publish_stream";
//dicParams ["scope"] ="publish_stream";
//long destinationID = 189415601106529;
//long accountID = Convert.ToInt64(System.Web.HttpContext.Current.Session ["UserId"]);
////如果需要,获取发布用户的访问令牌
//if(destinationID!= accountID)
//{
//dicParams ["access_token"] = this.getPostingUserAuthToken(destinationID);
//}
//publishResponse = this.FacebookConnection.Post("/" + destinationID +"/feed",dicParams);
Response.RedirectLocation ="http://192.168.10.57/samplefacebook/index.aspx";
Response.Redirect("https://graph.facebook.com/me/accounts?access_token=<ACCESS_TOKEN>");
}
//受保护的字符串postToWall()
//{
//var accessToken = Session ["_ FB_ACCESS_TOKEN"];
//var graphId = Session ["_ FB_USER_GRAPH_ID"];
//var url = string.Format("https://graph.facebook.com/{0}/feed",graphId);
//var req = WebRequest.Create(url);
//req.Method ="POST";
//req.ContentType ="application/x-www-form-urlencoded";
//字符串postData = string.Format(@"curl -F``access_token = {0}''-F``message = This is a test ...''https://graph.facebook.com/{1 }/feed,accessToken,graphId);
//byte [] byteArray = Encoding.UTF8.GetBytes(postData);
//var stream = req.GetRequestStream();
//stream.Write(byteArray,0,byteArray.Length);
//stream.Close();
//WebResponse response = req.GetResponse();
//Console.WriteLine(((((HttpWebResponse)response).StatusDescription));
//stream = response.GetResponseStream();
//StreamReader reader = new StreamReader(stream);
//返回reader.ReadToEnd();
//}
}
}
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Facebook;
using Facebook.Web;
using Facebook.Rest;
using Facebook.Schema;
using Facebook.Utility;
using Facebook.Winforms;
using Facebook.Session;
using System.Collections.Generic;
using Facebook.Winforms.Components;
using System.Web.UI.MobileControls;
using System.Net;
using System.IO;
using System.Text;
namespace FacebookDemo
{
public partial class index : System.Web.UI.Page
{
//K.Durga Nageswara Rao..............//
private const string APPID = "Your App Id";
private const string APPKEY = "Your App Key"; // From the Facebook application page
private const string SECRET = "Your App Secreat";
////Facebook.Web.FbmlControls.PromptPermission prompter = new Facebook.Web.FbmlControls.PromptPermission();
//Facebook.Session.ConnectSession session = new Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey, ConnectAuthentication.SecretKey);
//protected void Page_Load(object sender, EventArgs e)
//{
//string sessionKey = Session["facebook_session_key"] as String;
//string userId = Session["facebook_userId"] as string;
//string authToken = Request.QueryString["auth_token"];
//string accesstoken = Request.QueryString["code"];
//if (!String.IsNullOrEmpty(sessionKey))
//{
// session.SessionKey = sessionKey;
// //session.UserId = userId;
//}
//else if (!String.IsNullOrEmpty(authToken))
//{
// Session["facebook_session_key"] = session.SessionKey;
// Session["facebook_userId"] = session.UserId;
// Session["facebook_session_expires"] = session.SessionExpires;
//}
//else
//{
// Response.Redirect(@"http://www.facebook.com/login.php?api_key=" + APPKEY + @"&v=1.0");
//}
//if (ConnectAuthentication.isConnected())
//{
// // Facebook.Session.ConnectSession session = new Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey, ConnectAuthentication.SecretKey);
// string sessionkey = session.SessionKey;
// string UserId = session.UserId.ToString();
// //session.UserId = ConnectAuthentication.UserID;
// Facebook.Rest.Api api = new Facebook.Rest.Api(session);
// //Display user data captured from the Facebook API.
// Facebook.Schema.user user = api.Users.GetInfo();
// string fullName = user.first_name + " " + user.last_name;
// Panel1.Visible = true;
// Label1.Text = fullName;
//}
//else
//{
// //Facebook Connect not authenticated, proceed as usual.
//}
Facebook.Web.FbmlControls.PromptPermission prompter = new Facebook.Web.FbmlControls.PromptPermission();
protected void Page_Load(object sender, EventArgs e)
{
string authToken = Request.QueryString["auth_token"];
if (ConnectAuthentication.isConnected())
{
Facebook.Session.ConnectSession session = new Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey, ConnectAuthentication.SecretKey);
// session.UserId = ConnectAuthentication.UserID;
Facebook.Rest.Api api = new Facebook.Rest.Api(session);
//Display user data captured from the Facebook API.
Facebook.Schema.user user = api.Users.GetInfo();
string fullName = user.first_name + " " + user.last_name;
Panel1.Visible = true;
Label1.Text = fullName;
Facebook.Schema.pages_getInfo_response pageinfo = new pages_getInfo_response();
System.Web.HttpContext.Current.Session["sessionkey"] = session.SessionKey;
System.Web.HttpContext.Current.Session["UserId"] = session.UserId;
System.Web.HttpContext.Current.Session["AccessToken"] = session.SessionSecret;
//var val = HttpContext.Current.Request.Cookies["b90e89f2fcf265f26708476a186b1222_user"].Values;//100002386562731
//var val0 = HttpContext.Current.Request.Cookies["b90e89f2fcf265f26708476a186b1222"].Values;//4febeb45d23f49fa9d793c29da703336
//var val1 = HttpContext.Current.Request.Cookies["b90e89f2fcf265f26708476a186b1222_ss"].Values;//AQA9rwe7RanXzDeV
//var val2 = HttpContext.Current.Request.Cookies["b90e89f2fcf265f26708476a186b1222_session_key"].Values;//2.AQD709Yz-kp5xWcg.3600.1306418400.1-100002386562731
//var val3 = HttpContext.Current.Request.Cookies["b90e89f2fcf265f26708476a186b1222_expires"].Values;//1306418400
}
else
{
if(string.IsNullOrEmpty(ConnectAuthentication.SessionKey))
{
//Page_Load(sender,e);
}
// Response.Redirect(@"http://www.facebook.com/login.php?api_key=" + APPKEY + @"&v=1.0");
}
//postToWall();
//string signedRequest = Request.Form["signed_request"];
//var DecodedSignedRequest = FacebookSignedRequest.Parse(FacebookContext.Current.AppSecret, SignedRequest);
//dynamic SignedRequestData = DecodedSignedRequest.Data;
//var RawRequestData = (IDictionary<string, object>)SignedRequestData;
//if (RawRequestData.ContainsKey("page") == true)
//{ Facebook.JsonObject RawPageData = (Facebook.JsonObject)RawRequestData["page"];
// if (RawPageData.ContainsKey("id") == true)
// currentFacebookPageID = (string)RawPageData["id"];
//}
}
protected void Button1_Click(object sender, EventArgs e)
{
Facebook.Session.ConnectSession session1 = new Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey, ConnectAuthentication.SecretKey);
if (ConnectAuthentication.isConnected())
{
//ConnectAuthentication.UserID = System.Web.HttpContext.Current.Session["UserId"];
FacebookService fbService = new FacebookService();
//fbService.SessionKey = session1.SessionKey;
fbService.uid = session1.UserId;
//fbService.ApplicationKey = ConnectAuthentication.ApiKey;
attachment attach = new attachment();
//attach.caption = "Check this out...";
//attach.description = "Posting from my Facebook development App";
//attach.href = "http://www.kennetham.com/";
//attach.name = "Attach my web link via FacebookAPI";
attachment_media attach_media = new attachment_media();
attach_media.type = attachment_media_type.image;
attachment_media_image image = new attachment_media_image();
image.type = attachment_media_type.image;
image.href = "http://profile.ak.fbcdn.net/static-ak/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif";
image.src = "http://profile.ak.fbcdn.net/static-ak/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif";
List<attachment_media> attach_media_list = new List<attachment_media>();
attach_media_list.Add(image);
attach.media = attach_media_list;
//attachment_property attach_prop = new attachment_property();
///* action links */
//List<action_link> actionlink = new List<action_link>();
//action_link al1 = new action_link();
//al1.href = "http://www.kennetham.com/";
//al1.text = "Kenneth Ham";
//actionlink.Add(al1);
Facebook.Session.ConnectSession session = new Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey, ConnectAuthentication.SecretKey);
//session.UserId = ConnectAuthentication.UserID;
Facebook.Rest.Api api = new Facebook.Rest.Api(session);
//Display user data captured from the Facebook API.
string publishAccess = api.ExtendedPermissionUrl(Facebook.Schema.Enums.ExtendedPermissions.publish_stream);
Uri uri= new Uri(String.Format("https://graph.facebook.com/189415601106529/feed?api_key={0}&v=1.0&ext_perm={1}&message=uuuuhhhuuu...&method=post", ConnectAuthentication.ApiKey, publishAccess));
Response.Redirect(uri.ToString());
// api.Stream.Publish(TextBox1.Text, attach, actionlink, fbService.uid.ToString(), 0);
api.Stream.Publish(TextBox1.Text, null, null, fbService.uid.ToString(), 0);
}
else
{
//Facebook Connect not authenticated, proceed as usual.
}
}
private static Uri GetExtendedPermissionUrl(Enums.ExtendedPermissions permission)
{
return new Uri(String.Format("http://www.facebook.com/authorize.php?api_key={0}&v=1.0&ext_perm={1}", ConnectAuthentication.ApiKey, permission));
//return new Uri(String.Format("https://graph.facebook.com/189415601106529/feed?api_key={0}&v=1.0&ext_perm={1}&message=uuuuhhhuuu...&method=post", ConnectAuthentication.ApiKey, permission));
//https://graph.facebook.com/<Page_ID>/feed?access_token=<PAGE_ACCESS_TOKEN_TAKEN_FROM_STEP2>&message=uuuuhhhuuu...
}
protected void Button2_Click(object sender, EventArgs e)
{
Enums.ExtendedPermissions perm;
perm = Enums.ExtendedPermissions.publish_stream;
Uri uri = GetExtendedPermissionUrl(perm);
Response.Redirect(uri.ToString());
}
protected void Button3_Click(object sender, EventArgs e)
{
//Facebook.Session.ConnectSession session1 = new Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey, ConnectAuthentication.SecretKey);
//this.Session.Remove("USER_ID");
//this.Session.Remove("FACEBOOK_USER_INFO");
//try
//{
// if (ConnectAuthentication.SessionKey!= null)
// {
// if (ConnectAuthentication.isConnected())
// {
// this.Session.Clear();
// } // end if
// } // end if
//}
//catch (Exception ex)
//{
//} // end catch
//this.Response.Redirect("~/index.aspx", true);
//to post message to fan pages...........
//dynamic messagePost = new ExpandoObject();
//messagePost.access_token = "[YOUR_ACCESS_TOKEN]";
//messagePost.picture = "[A_PICTURE]";
//messagePost.link = "[SOME_LINK]"; messagePost.name = "[SOME_NAME]";
//messagePost.caption = "{*actor*} " + "[YOUR_MESSAGE]";
////<---{*actor*} is the user (i.e.: Aaron)
//messagePost.description = "[SOME_DESCRIPTION]";
//FacebookClient app = new FacebookClient("[YOUR_ACCESS_TOKEN]");
//try {
// var result = app.Post("/" + [PAGE_ID] + "/feed", messagePost);
//} catch (FacebookOAuthException ex)
//{
// //handle something
//}
}
private IList<page> GetInfo(List<string> fields, List<long> page_ids, long? uid, bool isAsync, Facebook.Rest.Pages.GetInfoCallback callback, Object state)
{
var parameterList = new Dictionary<string, string> { { "method", "facebook.pages.getInfo" } };
Utilities.AddList(parameterList, "fields", fields);
Utilities.AddList(parameterList, "page_ids", page_ids);
Utilities.AddOptionalParameter(parameterList, "uid", uid);
parameterList["fields"] = parameterList["fields"].Replace("''", "");
if (isAsync)
{
SendRequestAsync<pages_getInfo_response, IList<page>>(parameterList, !string.IsNullOrEmpty(System.Web.HttpContext.Current.Session["sessionkey"].ToString()), new FacebookCallCompleted<IList<page>>(callback), state, "page");
return null;
}
var response = SendRequest<pages_getInfo_response>(parameterList, !string.IsNullOrEmpty(System.Web.HttpContext.Current.Session["sessionkey"].ToString()));
//return response == null ? null : response.page;
return null;
}
private object SendRequest<T1>(Dictionary<string, string> parameterList, bool p)
{
throw new NotImplementedException();
}
private void SendRequestAsync<T1, T2>(Dictionary<string, string> parameterList, bool p, FacebookCallCompleted<IList<page>> facebookCallCompleted, object state, string p_5)
{
throw new NotImplementedException();
}
protected void Button3_Click1(object sender, EventArgs e)
{
//var dicParams = new Dictionary<string, object>();
//dicParams["message"] = " r u fine";
//dicParams["caption"] = string.Empty;
//dicParams["description"] = string.Empty;
//dicParams["name"] = "sample fan page message";
//dicParams["req_perms"] = "publish_stream";
//dicParams["scope"] = "publish_stream";
//long destinationID = 189415601106529;
//long accountID=Convert.ToInt64(System.Web.HttpContext.Current.Session["UserId"]);
//// Get the access token of the posting user if we need to
//if (destinationID != accountID)
//{
// dicParams["access_token"] = this.getPostingUserAuthToken(destinationID);
//}
//publishResponse = this.FacebookConnection.Post("/" + destinationID + "/feed", dicParams);
Response.RedirectLocation = "http://192.168.10.57/samplefacebook/index.aspx";
Response.Redirect("https://graph.facebook.com/me/accounts?access_token=<ACCESS_TOKEN>");
}
//protected string postToWall()
//{
// var accessToken = Session["_FB_ACCESS_TOKEN"];
// var graphId = Session["_FB_USER_GRAPH_ID"];
// var url = string.Format("https://graph.facebook.com/{0}/feed", graphId);
// var req = WebRequest.Create(url);
// req.Method = "POST";
// req.ContentType = "application/x-www-form-urlencoded";
// string postData = string.Format(@"curl -F ''access_token={0}'' -F ''message=This is a test...'' https://graph.facebook.com/{1}/feed", accessToken, graphId);
// byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// var stream = req.GetRequestStream();
// stream.Write(byteArray, 0, byteArray.Length);
// stream.Close();
// WebResponse response = req.GetResponse();
// Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// stream = response.GetResponseStream();
// StreamReader reader = new StreamReader(stream);
// return reader.ReadToEnd();
//}
}
}
这篇关于如何使用ASP.net 2008从Facebook api 3.0发布消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文