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.
Related
I have a really frustrating issue, where all I want to do is get user images from O365 and simply display them on my web page, which is hosted on Azure azpp service.
As you can see from this SO and this SharePoint.StackExchange question, The images fail to load when simply trying to display the link taken from SharePoint in an <img> tag.
However, after navigating to the image in a a new tab, and refreshing my page, the iamges load fine. can anyone explain this behaviour? it makes no sense to me at all
Anyways since that just dont work for whatever reason (logged in user clearly has the right permissions, as the images do disaply after navigating to them),
I thought I would try downloading the images using graph API.
SO I downloaded the quick start project and trying to download the iamges with
public async Task<Stream> TestAsync(GraphServiceClient graphClient)
{
var users = graphClient.Users;
var jk = users["user.name#domain.com"];
return await jk.Photo.Content.Request().GetAsync();
}
But I just get
Exception of type 'Microsoft.Graph.ServiceException' was thrown.
Yet when I try to view the same image in the API graph explorer, I can download the image. Please can someone just help me to display SharePoint user images in my web page without the user having to first navigate to the image directly.. Why must it be so difficult?
Once you have a valid token, make sure your permission scopes include User.Read.All, for example:
The query:
var user = graphClient.Users["<userPrincipalName>"];
corresponds to the following endpoint
Url: /users/{userPrincipalName}
Method: GET
which requires User.Read.All scope, see permission section for a more details.
In addition, in case of access without a user token requires Administrative Consent before it can be used.
Example
var users = graphClient.Users;
var user = users[accountName];
var photo = await user.Photo.Content.Request().GetAsync() as MemoryStream;
using (var file = new FileStream("./user.jpg", FileMode.Create, FileAccess.Write))
{
if (photo != null) photo.WriteTo(file);
}
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);
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.
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
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.