Creating an album on a Page - c#

I am trying to post make a album and upload photos to a page on facebook that I have administrative rights to. It works using my facebook account's ID found on Find my facebook ID but it doesn't work when I use my page's ID. This is my code for creating the album.
var facebookClient = new FacebookClient(Properties.Settings.Default.AccessToken);
dynamic parameters = new ExpandoObject();
parameters.name = AlbumName;
parameters.description = AlbumDescription;
parameters.uid = AlbumOwnerID;
var fbResult = facebookClient.Post(string.Format("/{0}/Albums", AlbumOwnerID), parameters);
And this is the error that I get.

Related

C# Facebook app / post on site

im very new with Facebook apps and read several threads for creating them, but I have some problems with it.
First of all what I want to do: I want to create a web application that is able to post pictures, text and links on a facebook page that is managed by me.
I used the Facebook C# SDK: here!
What I have:
string facebookPageId = "<my page id>";
string app_id = "<my app id>";
string app_secret = "<my app secret>";
string scope = "publish_stream,manage_pages";
var fb = new FacebookClient();
dynamic res = fb.Get("oauth/access_token", new
{
client_id = app_id,
client_secret = app_secret,
grant_type = "client_credentials"
});
var access_token = res.access_token;
dynamic messagePost = new ExpandoObject();
messagePost.access_token = access_token;
messagePost.link = "http://www.test.at";
messagePost.name = "Testbot";
messagePost.caption = "{*actor*} " + "hello this is a test";
messagePost.description = "[SOME_DESCRIPTION]";
FacebookClient app = new FacebookClient(access_token);
app.AppId = app_id;
app.AppSecret = app_secret;
try
{
var result = app.Post("/hrechttest" + "/feed", messagePost);
}
catch (Exception e)
{
}
Well the code runs without any exceptions but in the output window I get the following:
Exception thrown: 'Facebook.FacebookOAuthException' in Facebook.dll
The next problem is:
As I understood it you must link your facebook app with your facebook page, but when I want to do that I cant select the page:
So what I did wrong or missed?
publish_stream is deprecated since many years, publish_pages is the correct permission to post to a Page (as Page).
API reference: https://developers.facebook.com/docs/graph-api/reference/page/feed#publish
Make sure you are using a Page Token, not a User Token:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
How to create Page Apps is explained in the docs too: https://developers.facebook.com/docs/pages/tabs

Given URL is not allowed by the Application configuration on c# web browser

I am trying to integrate Facebook authentication into my Windows desktop application using Facebook C# SDK. I tried to have user login using Facebook with a WebBrowser in an area of my application window. The WebBrowser will always show Given URL is not allowed by the Application configuration.
What URL should I give to my App Setting? Because my application will not be on a web page and Facebook App Setting does not have Windows Desktop platform.
private Uri GenerateFBLoginUrl(string appId, string extendedPermissions)
{
// reference: "http://blog.prabir.me/posts/facebook-csharp-sdk-writing-your-first-facebook-application-v6"
// var parameters = new Dictionary<string,object>
// parameters["client_id"] = appId;
dynamic parameters = new ExpandoObject();
parameters.client_id = appID;
parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";
// The requested response: an access token (token), an authorization code (code), or both (code token).
parameters.response_type = "token";
// list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display
parameters.display = "popup";
// add the 'scope' parameter only if we have extendedPermissions.
if (!string.IsNullOrWhiteSpace(extendedPermissions))
parameters.scope = extendedPermissions;
// generate the login url
var fb = new FacebookClient();
return fb.GetLoginUrl(parameters);
}
private void FacebookLogin()
{
loginUrl = GenerateFBLoginUrl(appID, "id");
this.FBLogin.Navigate(loginUrl.AbsoluteUri);
}
I am not familiar with this but I have two suggestions: 1) if you pass a null string what happens? and 2) pass a arbitrary URL. Good luck.

facebook upload photo as company page

I have a question regarding using facebook graph API (OAuth) to upload photo.
I have created one company page under my account.
When I use my account to upload photo to my company page, my user name appears as a user who uploaded the page.
Is there anyway I can upload page so that company name appears?
Below is the code that I currently implemented.
string access_token = FacebookSystem.RetrieveToken(UserEmail, AppID);
string query = string.Empty;
if (string.IsNullOrEmpty(PageID) || PageID.Equals("default", StringComparison.InvariantCultureIgnoreCase))
{
query = "me/photos";
}
else
{
query = string.Format("{0}/photos", PageID);
}
var fb = new FacebookClient(access_token);
try
{
dynamic parameters = new ExpandoObject();
foreach (string i in args.FileList)
{
parameters.message = args.Comment;
parameters.source = new FacebookMediaObject
{
ContentType = "image",
FileName = Path.GetFileName(i)
}.SetValue(File.ReadAllBytes(i));
fb.Post(query, parameters);
}
}
in order to use Graph API on behalf of a Page, you need to get Page access token - see here for more details: https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens
Authenticate the user and request the manage_pages permission
Get the list of pages the user manages from (1): https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
Parse the list and get the token - and use it to post to the feed.
you will do (1) in graph API explorer - and you will get user token. Then insert that token into URL in (2) - and you will see all your pages and corresponding token. Take the one you need and use it in your C# code to upload images.

Facebook posts not showing on timeline

I have created webapp in .Net MVC which shares post on Facebook. Here is the code of sharing post
var fb = new FacebookClient(facebookAccessToken);
var argList = new Dictionary<string, object>();
argList["name"] = postName;
argList.Add("picture", postImageUrl);
argList["link"] = postUrl;
var actions = new[] { new { name = "More Details", link = morePostDetailsUrl } }.ToList();
argList["actions"] = JsonConvert.SerializeObject(actions);
var postResult = fb.Post("<facebookuserId>/feed", argList);
Now i am able to post this feed successfully but these posts are not being displayed on timeline. I have checked all permission & they are set to public. Also i can see them in activity logs & on Home screen when i logs in.
How to post a feed so that it can be displayed on timeline automatically ?
Also i am using actions, are these actions being deprecated or do i need to submit them for review before going live ?
Please guide me if anyone has some idea on the above.
Thanks

Passing parameters to Facebook Open Graph API

I'm trying to upload a video to the Facebook open graph using the C# SDK. The video seems to upload fine and I get an Id for the activity, but only the sample metadata appears.
After a little digging, I found this:
Before being able to publish an Open Graph action for a user and having define its corresponding connected object type in Step 3, you will now need to create a publicly accessible web page that represents this object using Open Graph metatags. Once this object page is created, you can use the Graph API to publish an action.
Since this is a client-side app, I don't have a web page that I can refer Facebook to. So how do I pass in the right parameters?
Here's my code:
var parameters = new Dictionary<string, object>();
parameters["source"] = new FacebookMediaObject { ContentType = "video/mpeg", FileName = "video.mpeg" }.SetValue(File.ReadAllBytes(#"D:\sample video.MP4"));
parameters["og:title"] = "Sample video";
parameters["title"] = "Sample video";
parameters["og:description"] = "Test description";
parameters["highlight"] = "http://samples.ogp.me/287287444686523"; // If I don't put this, the upload fails
fb.PostAsync("/me/myobjectname:share", parameters);
Thanks!
For version 6, you can do:
var fb = new FacebookClient(accessToken);
string attachementPath = #"C:\image.jpg";
using (var stream = File.OpenRead(attachementPath))
{
dynamic result = fb.Post("me/photos",
new
{
message = "upload using Facebook C# SDK",
file = new FacebookMediaStream
{
ContentType = "image/jpg",
FileName = Path.GetFileName(attachementPath)
}.SetValue(stream)
});
}
More details here.

Categories