Posting emdedded HTML and JavaScript to Facebook - c#

I know how to post a message, etc. to a Facebook wall, but I want to post a custom HTML and JavaScript Facebook wall, and I want that HTML/JavaScript code to appear so users can use that from Facebook without leaving Facebook, like embedded YouTube videos I have seen this to be possible...
I use this to post to Facebook:
FacebookWebClient client = new FacebookWebClient();
// Post to user's wall
var postparameters = new Dictionary<string, object>();
postparameters["message"] = "Hello world!";
postparameters["name"] = "This is a name";
postparameters["link"] = "http://thisisalink.com;
postparameters["description"] = "This is a description";
var result = client.Post("/me/feed", postparameters);
How do I do this?
Maybe something like
postparameters["html"] = "html or view";
If it is not possible, how do I post SWF content with Flash parameters?

There is no way to post custom HTML or JavaScript code into a Facebook post because of security issues.
But you can still customize a lot of stuff like the link and the image, if you want to add an action link next to "Like, comment".
Find a lot more about publishing a post in Core Concepts › Graph API › Post.

if it is not possible, how do I post SWF content with Flash parameters?
To post an SWF video, you will need to do some work.
First, create a page that the SWF videos lives on where you can specify Open Graph meta tags. Read
more in The Open Graph protocol.
Then you need to create a post with a link to that page with the Open Graph tags. Then use the "link" parameter of the post object to point to the SWF file.

Related

Facebook page /feed missing images

I was using the Facebook Public API Feed for the longest time and since they deprecated it I've been trying to find a replacement method in C#.
I am able to get my page posts but any post that contains images I only get the message and no images. After spending the past weekend trying to find a way I am desperate to know if anyone has had any success in getting full page post content from the Facebook C# SDK library.
Here is what I have and it works for getting the posts but they do not contain any images.
var fb = new FacebookClient
{
AppId = ConfigurationManager.AppSettings.Get("FacebookAppID"),
AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"),
AccessToken = ConfigurationManager.AppSettings.Get("FacebookAccessToken")
};
var pageFeed = string.Format("/v2.4/{0}/feed", _facebookPageId);
dynamic response = fb.Get(pageFeed);
Since the upgrade in Graph API v2.4. Only a limited set of data is sent via FB unless specifically requested. You should pass the fields parameter with the keyword of data which you would like to retrieve.
A list of keyword is available here
In your case, the request statement would be:
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,picture", _facebookPageId);
To get all pictures from a post: replace picture with attachments, as picture will return the very first picture linked to the post.
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,attachments", _facebookPageId);

Facebook Api post on behave of the user ( via tag )

I got the following question. When I place a status message for an user, I would like to add my Facebook page as reference. I have seen other posts where the tag "via" is placed under the capitation.
How do I achieve that?
I am using the C# SDK from Facebook. I am already able to post with the following code:
FacebookClient fbClient = new FacebookClient(accessToken);
var args = new Dictionary<string, object>();
args["place"] = objectFBID;
fbClient.Post("/me/feed", args);
What parameter is needed for the "via" tag. I tried the "from" parameter, however it didn't work!
Thanks in advance!
When posting on a wall, make sure the user has given the right permissions to the App. Otherwise alot of data is hidden. This was the case with my facebook account. When using a facebook account that has given full acces, all data is displayed.

Post Media to User/Page Wall in Facebook with C# SDK

I'm using Facebook .Net SDK(http://facebooksdk.net/) in my application. I need post an image to the wall of the user or his page.
I have this piece of code to try do this:
var postUrl = "<fbid>/feed";
var fbParameters = new Dictionary<string,object>();
fbParameters["message"] = postRequest.FacebookPostContent;
if (postRequest.MediaData != null && postRequest.MediaData.Length > 0)
{
var stream = new MemoryStream(postRequest.MediaData);
if (postRequest.ContentType.Equals("image/jpeg"))
{
postUrl = postUrl.Replace("/feed", "/photos");
fbParameters["picture"] = new FacebookMediaStream { ContentType = postRequest.ContentType, FileName = DateTime.UtcNow.ToString("ddmmyyyyhhmmss") + "-photo.jpeg" }.SetValue(stream);
}
}
if (!string.IsNullOrWhiteSpace(postRequest.FacebookPageId))
{
fbUserID = postRequest.FacebookPageId;
}
postUrl = postUrl.Replace("<fbid>", fbUserID);
var result = await facebookClient.PostTaskAsync(postUrl, fbParameters);
Look at my postUrl variable. I update the with the user ID in Facebook or the PageID if it is a page so the post should be properly posted in the right object. If there is some image to upload, so add it to the dictionary.
So, with it in mind, I have the following questions:
When the fbUserID is a user ID, the post happens perfectly, with the image and description but, when the ID is a PageID, only the description text is posted and image is just ignored(the user has the manage_page permissions so I dont think it is a permission issue). What I'm doing wrong that the image is not being posted to the page's wall?
If I want to post a video instead of a image, what should I change in this code?
Already saw many problems with other technologies here in SO but never a conclusive solution.
Thank you very much for the help, I really appreciate.
Regards,
Gutemberg
Got it!
Facebook creates a different section inside the page called Recent Posts by Others on Test Page where people allowed to post images will be there, like an attachment icon. In order to post directly to the page's feed/wall, all I need to do is instead of use the user access_token(even if user granted manage_pages permission) just use the access_token that comes in /me/accounts object for the respective page.
About the video post, I just set the ContentType to "video/mpeg" and at server instead of set picture parameter on dictionary, I've set the video field with the video byte[].
Thanks!
Regards,
As an alternative you could try the Share Content button shown in one of the answers here:
Upload video on Facebook using Graph REST API on Windows Phone 8.1
I found that to be easier than tackling authorization and manually posting.

Facebook Post a tag to another page

I am using C# winforms and C# Facebook SDK 6 to create an app that control my page and automate somethings.
In all posts in my page i put tags in the text to other pages so i want to know how to post a tag in my page posts using Facebook SDK and Facebook graph API.
I tried the message_tag parameter in different scenarios but it didn't work maybe i am using it wrong, the code below is one of the senarios :
dynamic postParameters = new ExpandoObject();
postParameters.message = textToPostTextBox.Text;
postParameters.message_tags = new { id = "page_to_tag_id", name = "PageName", type = "page", offset = 3, length = 4 };
dynamic result = fb.Post("my_page_id/feed", postParameters);
Notes : a tag to page is when you type "#" and write the page or person name.
Please help me i searched a lot online and i tried my self but it didn't work and sorry for my bad English.
Like said CBroe said, the bug got disabled because of too much abuse , But always there is a way ,
i know someone who did it, and this is how : he wrote a statue on facebook then he intercept the request sent from the browser and modify it to have a tag with customized text, I didn't try it but I know that it works

Problem obtaing profile pictures from Facebook Graph API

Have gotten the foundation in place, but now, finding myself wanting to play around with my
application's user's profile pictures; I'm stumped....and have been for quite some hours...
Firstly, my oauth_token / access_token is obtained, using the official (though Alpha ;-)
Facebook C# SDK and only utilize the Graph API.
FBapi.Get("/" + friend.Dictionary["id"].String + "/picture");
leads to an exception due to not returning a JSONObject, and
using the complete http://graph.facebook.com/me/picture is forwarded/translated to the image's URL.
Trying a more direct approach didn't pan out either :
WebClient wcImg = new WebClient();
wcImg.DownloadFile("/" + friend.Dictionary["id"].String + "/picture", "name_blame.jpg");
Some details are lacking in my question; I beg your pardon, am very tired and will edit later if uproar commences.
Ideas?
Addendum :
Boy, afflicted by code blindness I was indeed! However, your sensibility gave me what I needed (Zynga, tremble in my canvas ;-).
For sake of curiosity...it appears there's no JSON template(pardon my lack of lingo) available for profile pictures? Then how do one go about obtaining a fleshed out, Graph API Photo of that profile picture (if available)?
The picture in Graph API is a bit special animal. It doesn't return json, it directly forwards to the image. It was made so that you can use this url right in html:
<img src="http://graph.facebook.com/<UID>/picture"> - displays avatar
Now if you need to know actual picture URL it redirects to there are 2 options:
Read redirect headers from that graph URL.
Use FQL:
select pic_square from user where uid=12345
There is alot of other info that can be extracted about a user using FQL (including pictures in other sizes).
Also, if You want to show big profile photo, use this:
http://graph.facebook.com/<UID>/picture?type=large
You can get ALL friends' profile pictures (direct Links to the photos), in a single GET request:
https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture
Then use Json to Decode the string.. and that's all...
NJoy ^_^

Categories

Resources