how to create a facebook event by using facebook api in asp.net - facebook

How to create a facebook event by using facebook api in asp.net.
Thanks.

public string CreateEvent(string accessToken)
{
FacebookClient facebookClient = new FacebookClient(accessToken);
Dictionary<string, object> createEventParameters = new Dictionary<string, object>();
createEventParameters.Add("name", "My birthday party )");
createEventParameters.Add("start_time", DateTime.Now.AddDays(2).ToUniversalTime().ToString());
createEventParameters.Add("end_time", DateTime.Now.AddDays(2).AddHours(4).ToUniversalTime().ToString());
createEventParameters.Add("owner", "Balaji Birajdar");
createEventParameters.Add("description", " ( a long description can be used here..)");
//Add the "venue" details
JsonObject venueParameters = new JsonObject();
venueParameters.Add("street", "dggdfgg");
venueParameters.Add("city", "gdfgf");
venueParameters.Add("state", "gfgdfgfg");
venueParameters.Add("zip", "gfdgdfg");
venueParameters.Add("country", "gfdgfg");
venueParameters.Add("latitude", "100.0");
venueParameters.Add("longitude", "100.0");
createEventParameters.Add("venue", venueParameters);
createEventParameters.Add("privacy", "OPEN");
createEventParameters.Add("location", "fhdhdfghgh");
//Add the event logo image
FacebookMediaObject logo = new FacebookMediaObject()
{
ContentType = "image/jpeg",
FileName = #"C:\logo.jpg"
};
logo.SetValue(File.ReadAllBytes(logo.FileName));
createEventParameters["#file.jpg"] = logo;
JsonObject resul = facebookClient.Post("/me/events", createEventParameters) as JsonObject;
return resul["id"].ToString();
}
I am using facebook graph apis with FacebookSdk from codeplex.
I am not able to post the venue with this code due to the open bug in facebook API. Other things work fine. I suggest you implement this venue parameters as well so that the functionality will work as soon as facebook resolves this issue.
Mark this as answer if it works for you.It will also help other people to save time on searching.

You might try this http://developers.facebook.com/docs/api

Related

tagging a friend in a facebook post c# sdk

I am trying to test the ability to tag friends in messages from our app. It posts to facebook just fine, caption, description, name, picture, and link all display as they should, but in message all it shows is the string in p_message.
string token = Request.Cookies["fbToken"]["value"];
var fbclient = new FacebookClient(token);
var args = new Dictionary<string, object>();
args["message"] = p_message + " #[1550577341:nick.rich.1232]";
args["caption"] = "This is caption!";
args["description"] = "This is description!";
args["name"] = "This is name!";
args["picture"] = "http://nowprovemewrong.com/Images/icon-2.png";
args["link"] = str_redirect_uri;
fbclient.Post("me/feed", args);
formatting #[id:username] any differently results in it appearing in the message, so i'm assuming facebook is recognizing it as something just not a tag
You are not allowed to tag messages like this. The feature #[1550577341:nick.rich.1232] exists but it's for use in Open Graph tagging.
see: https://developers.facebook.com/docs/opengraph/guides/tagging/#mentions

Using Facebook C# SDK to post to page

I've been using the Facebook C# SDK for sometime now, but have a really old version and am still using the REST API (I think). I'm just concerned with using the API to post to my own Facebook page (I have a WCMS plugin that posts content to our institution's Facebook page). I was wondering if anyone knew of a good tutorial on how to get this setup with the latest version of the SDK? I'm also concerned with how this is going to work when offline_access goes away so any thoughts on that would be appreciated as well. I'd rather not have to go in an manually get a new access token every 60 days. This seems somewhat unnecessary since the app I'm using to do the posting is in the same FB account as the page I'm trying to post to.
Here's one way to do it:
public static string RefreshTokenAndPostToFacebook(string currentAccessToken)
{
string newAccessToken = RefreshAccessToken(currentAccessToken);
string pageAccessToken = GetPageAccessToken(newAccessToken);
PostToFacebook(pageAccessToken);
return newAccessToken; // replace current access token with this
}
public static string GetPageAccessToken(string userAccessToken)
{
FacebookClient fbClient = new FacebookClient();
fbClient.AppId = "app id";
fbClient.AppSecret = "app secret";
fbClient.AccessToken = userAccessToken;
Dictionary<string, object> fbParams = new Dictionary<string, object>();
JsonObject publishedResponse = fbClient.Get("/me/accounts", fbParams) as JsonObject;
JArray data = JArray.Parse(publishedResponse["data"].ToString());
foreach (var account in data)
{
if (account["name"].ToString().ToLower().Equals("your page name"))
{
return account["access_token"].ToString();
}
}
return String.Empty;
}
public static string RefreshAccessToken(string currentAccessToken)
{
FacebookClient fbClient = new FacebookClient();
Dictionary<string, object> fbParams = new Dictionary<string, object>();
fbParams["client_id"] = "app id";
fbParams["grant_type"] = "fb_exchange_token";
fbParams["client_secret"] = "app secret";
fbParams["fb_exchange_token"] = currentAccessToken;
JsonObject publishedResponse = fbClient.Get("/oauth/access_token", fbParams) as JsonObject;
return publishedResponse["access_token"].ToString();
}
public static void PostToFacebook(string pageAccessToken)
{
FacebookClient fbClient = new FacebookClient(pageAccessToken);
fbClient.AppId = "app id";
fbClient.AppSecret = "app secret";
Dictionary<string,object> fbParams = new Dictionary<string,object>();
fbParams["message"] = "Test message";
var publishedResponse = fbClient.Post("/your_page_name/feed", fbParams);
}
I would recommend you start by reading this blog post. http://blog.prabir.me/post/Facebook-CSharp-SDK-Writing-your-First-Facebook-Application-v6.aspx
And this documentation http://csharpsdk.org/docs/making-synchronous-requests
http://blog.prabir.me/post/Facebook-CSharp-SDK-Making-Requests.aspx
and find graph api post
i hope one day prabir and nathan will finish web site docs and we will learn it clearly.for now.just digg the web.

How to post images to facebook via windows phone?

In my application image has to post to Facebook,mail.Sorry i am new to windows phone.i don't have a idea.please help me.what i can do first.
If you want to share a status you can use your facebook account on your phone using Share link task (with this method you can only post on your wall) http://msdn.microsoft.com/en-us/library/hh394027%28v=vs.92%29.aspx
To post (pictures, messages or others) on every wall you have access you need some things :
First you need to create a facebook application using this link :
Facebook developers
After that you need to identify yourself using a WebBrowser control with the link related to your application. The application requests authorization to perform certain actions such as posting. You need to detail the authorizations like this :
Dictionary<string, string> uriParams = new Dictionary<string, string>() {
{"client_id", "your app id"},
{"response_type", "token"},
{"scope", "user_about_me, offline_access, publish_stream"}, //The rights
{"redirect_uri", "http://www.facebook.com/connect/login_success.html"},
{"display", "touch"}
};
The Dictionary also contains the redirection uri to define if the operation was successful.
Finally you are authentified and receive an access token. Now you can use a WebRequest POST to post a message using this token :
WebRequest request = HttpWebRequest.Create("https://graph.facebook.com/" + the id of your wall + "/feed");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.BeginGetRequestStream((reqResult) =>
{
using (Stream strm = request.EndGetRequestStream(reqResult))
using (StreamWriter writer = new StreamWriter(strm))
{
writer.Write(client.AccessToken);
writer.Write("&message=" + HttpUtility.UrlEncode(status));
}
request.BeginGetResponse((result) =>
{
try
{
var response = request.EndGetResponse(result);
using (var rstrm = response.GetResponseStream())
{
var serializer = new DataContractJsonSerializer(typeof(FacebookPostResponse));
var postResponse = serializer.ReadObject(rstrm) as FacebookPostResponse;
callback(true, null);
}
}
catch (Exception ex)
{
callback(false, ex);
}
}, null);
}, null);
Here is how to post a message on a facebook page,
You should give the Facebook C# SDK a try
Facebook C# SDK
I have built this in once in an app of mine. They have plenty examples available which should be useful.

How to mention user/page in post on wall using facebook api?

I've found format
#[id:1:anchor]
where id is user id or page id and anchor is text displayed.
This format is not documented on official facebook dev page, thus working.
What is the status of issue? Are there any alternatives?
There is no way to add tags in text this way via the API. There were loopholes which allowed this to work but they were closed shortly afterwards
i got the solution for this, here the using c# code:
protected void btnPost_Click(object sender, EventArgs e)
{
var client = new FacebookClient("YOUR FB TOKEN HERE");
var parameters = new Dictionary<string, object>
{
{"message", "YOUR STATUS HERE" },
{"tags" , "YOUR FRIENDS FB ID HERE"},
{"place" , "YOUR PLACE ID HERE"}
};
client.Post("me/feed", parameters);
lblPost.ForeColor = System.Drawing.Color.Red;
lblPost.Text = "Status Updated!";

How to post image on facebook fan page using C# facebook sdk on codeplex

Currently I'm working on my HTML 5 ASP.Net Application,
Which has requirement of Graffiti Wall, When user draw something on my Wall(means on my HTML 5 Canvas element), and Press Share Button on my Page, at that time the whole picture should need to be post on one of the Facebook Page.
Now my question is that is this thing possible using C# facebook sdk by codeplex ?
if its possible, than how to post image on facebook fan page using this SDK??
Where can I get the good resource the implement this kind of functionality or similar code.
I've check the all examples given by them, there is no any example which post on the facebook fan page.
Or even other library that can implement this kind of functionality.
I've check this library, and see that it has FacebookClient,ExpandoObject, FacebookMediaObject kind of classes, but how to and where to use this classes,where are the description and sample code.
Thanks,
Jigar Shah
you can post to others wall using "{id}/feed"
if you want to post image/video on wall. Try downloading the samples from nuget.
Install-Package Facebook.Sample
Here is how to do using the graph api.
public static string UploadPictureToWall(string id, string accessToken, string filePath)
{
var mediaObject = new FacebookMediaObject
{
FileName = System.IO.Path.GetFileName(filePath),
ContentType = "image/jpeg"
};
mediaObject.SetValue(System.IO.File.ReadAllBytes(filePath));
try
{
var fb = new FacebookClient(accessToken);
var result = (IDictionary<string, object>)fb.Post(id + "/photos", new Dictionary<string, object>
{
{ "source", mediaObject },
{ "message","photo" }
});
var postId = (string)result["id"];
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;
}
}