Post to a friends wall - c#

I have an MVC4 application that uses OAuth to login via facebook. Once logged in the user can then choose a guestlist from their Facebook Friends. This is fine as I am managing to retrieve the facebook Friends and their ID's.
Now I want to be able to post to the Friends wall a message from the application. Is this possible at th moment as there seems to have been a lot of changes to what Facebook allows you to do, if a wall post is not possible, can a private message be sent?
I have no code snippets from this one, just direction would be appreciated.
Thanks

I have used this code for posting on friend wall
var fbApplication = new DefaultFacebookApplication { AppId = fbapp, AppSecret = fbsec };
var current = new FacebookWebContext(fbApplication);
Facebook.Web.FacebookWebClient client = new Facebook.Web.FacebookWebClient(token);
//client.AccessToken = current.AccessToken;
dynamic parameters = new ExpandoObject();
parameters.message = "";
parameters.link = link;
parameters.name = name;
parameters.caption = caption;
parameters.description = desc;
parameters.from = fromId;//your fb ID
//friendId will be the ID of the person,you wants to post on wall
object resTest = client.Post("/" + friendId + "/feed", parameters);
Alternatively you can use Graph API's feed dialog
check this

Related

C# sharing content on Facebook

First thing first, I never used SDK before and I don't know what does token mean. I am searching for the most simple solution, if possible without SDK, without token, without FB App.
I have a button in my C# application and when the user clicks on it I want a popup window where the user can login to Facebook or if he is logged in he can push the share button in order to share the predefined content.
While searching on the internet I found this code:
var client = new FacebookClient("my_access_token");
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.actions = new {
name = "View on Zombo",
link = "http://www.zombo.com",
};
parameters.privacy = new {
value = "ALL_FRIENDS",
};
parameters.targeting = new {
countries = "US",
regions = "6,53",
locales = "6",
};
dynamic result = client.Post("me/feed", parameters);
But this example uses Facebook SDK and it needs token. I want a simple solution, without SDK, without FB APP. I want a simple popup with predefined text.
Is there any solution?
An access token is an opaque string that identifies a user, app, or page and can be used by the app to make graph API calls.
Access Tokens identifies an app ,user or page
Without creating an app from facebook and getting a token you cannot proceed in this case(c# application).

Post message from Website to Facebook wall

I have a website made with ASP.NET webform .NET 4.5 C#. This site contains a forum(homemade by me), parts of this forum needs to be posted to the specific facebook wall(made for this webpage). What I need :
Post just created thread(message) from specific part of the forum to the corsponding facebook wall.
Optional : Sync the forum thread on webpage with message/comments on the specific facebook page
I have looked at these guides :
http://www.codeproject.com/Articles/569920/Publish-a-post-on-Facebook-wall-using-Graph-API
http://www.c-sharpcorner.com/UploadFile/raj1979/post-on-facebook-users-wall-using-Asp-Net-C-Sharp/
But im not sure that this is really the solution for me? I have tried to follow the guide but it does not look the same.
Edit :
dynamic result;
//https://developers.facebook.com/tools/explorer/
//https://developers.facebook.com/tools/access_token/
FacebookClient client = new FacebookClient(ConfigurationManager.AppSettings["FacebookAppToken"]);
//result = client.Get("debug_token", new
//{
// input_token = ConfigurationManager.AppSettings["FacebookAppToken"],
// access_token = ConfigurationManager.AppSettings["FacebookAppToken"]
//});
//result = client.Get("oauth/access_token", new
// {
// client_id = ConfigurationManager.AppSettings["FacebookAppId"],
// client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
// grant_type = "client_credentials",
// //redirect_uri = "http://www.MyDomain.net/",
// //code = ""
// });
result = client.Get("oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["FacebookAppId"],
client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
grant_type = "client_credentials"
});
client.AccessToken = result.access_token;
result = client.Post("[IdOfFacebookPage]/feed", new { message = "Test Message from app" });
//result.id;
result = client.Get("[IdOfFacebookPage]");
return false;
Approach to post to a facebook wall:
You need to register in facebook developer tools.
Create a app (fill a form).
Download FGT 5.0.480 (Facebook graph toolkit)
Reference FGT dlls in your web application.
FGT has methods to post to facebook wall but needs appId.
Use the app id of your app created in step 2.
To post to an user's wall through facebook, it is only possible through an app.
Try this asp .net app, which will allow you to post in your wall:
https://apps.facebook.com/aspdotnetsample/?fb_source=search&ref=br_tf
This will allow you to envision what you need.
Your app gets an appId with which you need to generate auth token.
Limitation: The user's wall where you want to post should have added the app created at step 2, this is compulsory and there is no work around.
When the user accesses the app for the first time, it automatically asks for permission to post to wall--> the user needs to accept it.
Hope this gives you an idea on how to go about doing this.
You can then post into the user's wall.
For Banshee's below request using Facebook SDK for .NET:
userId - facebook user id, wall to post the message
This user should have added the app created by you in step 1 else it will say unauthorized access.
dynamic messagePost = new ExpandoObject();
messagePost.picture = "http://www.stackoverflow.com/test.png";
messagePost.link = "http://www.stackoverflow.com";
messagePost.name = "This is a test name";
messagePost.caption = "CAPTION 1";
messagePost.description = "Test desc";
messagePost.message = "message"
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new {
client_id = "app_id",
client_secret = "app_secret",
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
try
{
var postId = fb.Post(userId + "/feed", messagePost);
}
catch (FacebookOAuthException ex)
{
//handle oauth exception
}
catch (FacebookApiException ex)
{
//handle facebook exception
}
You will need an extended token to publish to a wall.. Steps to get extended token is explained well by Banshee..
Edit: How to get extended token by Banshee:
Please follow this post
By creating a extended page token and use it to make the post everything works just fine. See this : How to get Page Access Token by code?
Im surprised that this simple task was so hard to get running and that there was vary little help to get.

Can't send Notifications using C# Facebook SDK

I am trying to send a notification (not app requests) to registered users, server-side using the C# Facebook SDK. I actually get a success message, but no notification is sent. Our app is not in sandbox and has canvas enabled. The code below show attempts to send both notifications and app requests--the notifications do nothing, but the app request works:
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = "MY_APP_KEY",
client_secret = "MY_SECRET",
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
dynamic nparams = new ExpandoObject();
nparams.template = "Hello from my app!";
nparams.href = "Home";
dynamic requestParams = new ExpandoObject();
requestParams.message = "Hi there";
requestParams.title = "Please use this awesome app";
foreach (string facebookID in facebookIDs)
{
// This returns success:true, but doesn't actually do anything
var postResult = fb.Post(facebookID + "/notifications", nparams);
// This works and shows a request in the app center
var postResult2 = fb.Post(facebookID + "/apprequests", requestParams);
}
The fact that apprequests send here tells me the access token is ok, so why don't notifications work? We really need to do this server-side--has anyone been able to do that?
Got a response from facebook on this . . . basically, that this feature is in beta and it may just not work, despite giving Success responses
Good snippet Anthony. Appears to be working consistently now. +1 for your attempt.
PS: In case anyone stumbles upon this code, "facebookID" is a numeric Id and can be derived using the following link http://findmyfacebookid.com/

How to post to friend's notification area?

I have a web site facebook app. I can login and post to users wall.What I really want is when a user creates an image on my web site , he can create a notification on couple friends to take an action on the image. How can I do this ?
I have this code but I don't see a notification at my notification area ?
var f = new FacebookClient();
dynamic result = f.Get("oauth/access_token", new
{
client_id = FACEBOOK_APP_ID,
client_secret = FACEBOOK_SECRET,
grant_type = "client_credentials"
});
var token = result.access_token as string;
var reqClient = new FacebookClient(token);
var args = new Dictionary<string, object>();
args["message"] = "Invitation to action message";
args["data"] = "Invitation to action data";
var reqResult = reqClient.Post("/" + facebookId.ToString() + "/apprequests", args);
The app generated request go to the bookmarks counter and not to the top notifications (with the globe image).
There's no way for an app to send that kind of notification to a user (that I'm aware of).
You can check in the Social Channels guide on the options that are available for you, also you can check the Requests documentation.
Use app notifications. The guide I've linked to shows a lot of documentation.

Facebook C# SDK Send Gift

I want to send gift request to User rather than to post on wall is it possible?
I have access token of that User and i can send him post to wall but not know how i can send request or notification?
var app = new Facebook.FacebookClient(oAuthAccessToken);
dynamic parameters = new ExpandoObject();
parameters.message = "test";
parameters.category = "Application";
//category
dynamic id = app.Post("me/feed", parameters);
thanks

Categories

Resources