Publish content to Facebook - c#

I apologize if this has already been answered, but all the information out there on Facebook publishing is so confusing and conflicting, I haven't been able to get anything to work yet. I'm trying to set up an application that runs on my local server to publish content to my organization's fan page (this will tie in with my WCMS to cross-post content). I believe I want a Facebook Connect application to do this which I've set up properly in Facebook and gotten an application key and secret. Here's the code I'm trying to execute, but each time it's run I get "User has not authorized access" even if I'm just trying to publish to the application wall.
ConnectSession fbSession = new ConnectSession("APP_KEY", "APP_SECRET");
Api fbAPI = new Api(fbSession);
fbAPI.Stream.Publish("hello world");
I've also tried:
fbAPI.Stream.Publish("hello world", null, null, FAN_PAGE_ID, APP_ID);
I've granted my application access to publish on the fan page.
EDIT:
I've tried turning this into a Desktop application instead because it appears as though Javascript needs to be involved in order for it to be a Connect application. Here's the updated session initialization line. This now gives me a "Incorrect signature error."
DesktopSession fbSession = new DesktopSession("APP_KEY", false);

There is a similar question titled "How can I post to a facebook wall from a c# web service?" for which I provided a very lengthy answer, specifically indicating how to post to a page.

casperOne's solution works, however, I found this article to be the best solution.
http://tech.karolzielinski.com/publish-post-of-facebook-page-wall-as-a-page-not-a-user-python-facebook-rest-api
This authorizes the application to post directly to the Fan Page without having to go through an admin account.

Related

ASP.NET CORE 2.1 External Login

Am new to external logins in coding, so have started to get my head around the concepts but am still running into some issues.
Effectively there are 2 sites, both hosted on the same server, and as I load one up (Lets call it MySite), it should redirect to the second Site (Lets call it LogOn), where a user can logon using their credentials. LogOn then redirects back to MySite, with the credentials which can be used to see if they have the credentials to view this site, and shown messages or data dependent on their permissions
However right now, I can get it to redirect to LogOn. I've been experimenting getting it to redirect to Microsoft login and Google also, which redirects fine, but when I set up a WsFederation and add it to my authentication services I'm not quite sure what information to put in the Wtrealm section and metadataaddress options. Hopefully I have given enough information for someone to understand where I'm running into issues.
My code is shown below
services.AddAuthentication("MyCookieAuthenticationScheme")
.AddWsFederation("TestWs", WsOptions =>
{
WsOptions.Wtrealm = "http://SiteOnServer??";
WsOptions.MetadataAddress = "???";
WsOptions.RequireHttpsMetadata = false;
})
Any help would be greatly appreciated, just couldn't find a great deal of documentation taking you through the process.
Thanks in advance!

How do I post to a Facebook Page using the Graph API without having my Facebook App reviewed?

The Facebook documentation has this page called Posting as a Page which I've been following.
I followed the instructions on how to obtain an "immortal" access token for the Page.
I've used the Access Token Debugger to check my token is correct. It has the right AppID, the right ProfileID (for the page), and the right UserID (for the owner of the page). It expires "Never", it is valid, and it has the right scopes: manage_pages, publish_pages, publish_actions, public_profile.
I then used the Facebook SDK for .NET to make the call to the API to post to the Page.
var facebookClient = new FacebookClient(accessToken);
facebookClient.Post(string.Format("{0}/feed", profileID), new
{
message = message
});
The post appears on the Page and if I hover "globe" icon to see it's visibility/accessibility it says "public".
So, it worked right? Well ... no.
It turns out only users assigned a role in the Facebook App can see that post, despite it looking like a normal post and saying it's public. For any other users or those who are not signed in it simply doesn't appear.
The documentation page Page Access Tokens and Permissions says:
Your app might not need to request these permissions because people posting are already set up with a role in your app's dashboard. If this is the case you do not need to submit your app for review. See the Roles tab in App Dashboard.
I notice it says "people" which is a touch ambiguous. Does that mean only Users can publish to a Page without being reviewed? You can't publish as the Page itself without the review?
I've tried adding the page to the "Developers" and "Testers" roles for the app using the Pages ProfileID, but it says it can't resolve that to a UserID or name. That makes sense, roles are for people rather than pages.
EDIT 1:
I've tried using the "Embed Post" function and that gave me a link to the post. I tried using the link with a user that can't see the post and got:
It's not expired, as the users that can see it can still see it. It's interesting that it says you might not be in the audience that can view it, but it's set to public which I believe means everyone should see it.
You need to make your app “live” (see top of Status&Review tab), otherwise content created through it will only be visible to people with a role in the app.
(This has nothing to do with permission review.)

Facebook login throws "Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed

I know this question was already asked many times, but still It seems to throw this error altough I tried several url addresses.
I'm trying to make facebook login through a asp.net mvc app like in microsoft tutorial
here.
When I check it on local host it works fine (Site URL in facebook is set to: http://localhost:55797/
but when I try to check it after I upload the app to the server it gives me this error:
Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
My server's login page is: http://proj.ruppin.ac.il/igroup20/test1/Account/Login.aspx
I tried to write the following in my facebook app settings Site URL:
*http://proj.ruppin.ac.il/
*http://proj.ruppin.ac.il/igroup20/
*http://proj.ruppin.ac.il/igroup20/test1/
*http://proj.ruppin.ac.il/igroup20/test1/Account/
*http://proj.ruppin.ac.il/igroup20/test1/Account/Login.aspx
but none of them works for me.
this is my AuthConfig.cs:
public static void RegisterOpenAuth()
{
// See http://go.microsoft.com/fwlink/?LinkId=252803 for details on setting up this ASP.NET
// application to support logging in via external services.
//OpenAuth.AuthenticationClients.AddTwitter(
// consumerKey: "your Twitter consumer key",
// consumerSecret: "your Twitter consumer secret");
OpenAuth.AuthenticationClients.AddFacebook(
appId: "474928559284763",
appSecret: "****"); //hidden just for this question
//OpenAuth.AuthenticationClients.AddMicrosoft(
// clientId: "your Microsoft account client id",
// clientSecret: "your Microsoft account client secret");
//OpenAuth.AuthenticationClients.AddGoogle();
}
EDIT:
those are the screens that seems relevant to me, but I seem to have different gui, not like Tommy for example down here in this post:
EDIT2:
I just noticed there is a place for app domains and wrote there "proj.ruppin.ac.il" and in the web site url: "http://proj.ruppin.ac.il/igroup20/test1/" but still same error
For the benefit of searchers, I had the same when creating a test version of a site.
The answer was to go into the facebook site > Apps > My App > Settings > 'Advanced' tab and add the localhost address in the section titled 'Valid OAuth redirect URIs'.
Note: The same style of work will be required for an xyz.azurewebsites.net domain as well as a .com when you are testing.
Try this! These steps worked for my fb app hosted locally on http://localhost:3000/
Once signed in to your app on developers.facebook.com/...
Click Settings > Basic
Leave the "App Domains" field blank.
Click + Add Platform > Website
Use http://localhost:3000/ for both "Site URL" and "Mobile Site URL" fields
Click Save Changes
FINALLY!
You will need to update your App Domains as well in the Facebook Application configuration module to proj.ruppin.ac.il (Image taken from referenced tutorial to show that there are 2 places to update when changing FB app login URL)
Here's all the things I did to get this working
Nothing in "App Domains"
Put the server name (with port) in "Site URL"
In the "App Details" tab turn on your "Website" (I have the mobile website on) http://cl.ly/image/0h0D0L050Z2v (Why is this separate from setting the URL?)
Quadruple check your appid. I swear mine changed. But maybe I'm hallucinating that.
I got it to work with example.com in the settings. No http://www. It should work for you too (and you can add more that one domain.
Your issue is with your Facebook JavaScript SDK implementation and your Facebook app settings. The JS SDK is failing to initialize because it's been given the "wrong" settings.
The App Domain should be proj.ruppin.ac.il, and the Site URL should be http://proj.ruppin.ac.il/igroup20/test1/. It appears you've already done that. If so, make sure it saved properly, and you're not receiving any validation issues.
Lastly, go to your Facebook App's "Dashboard" and look for any warnings. For example, you may see Sandbox Mode is enabled; you may need to disable it before you can use the Facebook JS SDK.
Like others, I'm still seeing the "old" Facebook apps panel, but if you could provide a full screen capture of the "Dashboard" and "Settings" panes, we could be more helpful.
For the errors like top level domains are not allowed we need to provide both website and mobile url along with port number this works for me fine
you just need to also include the port number for your local host.
you can give the url like this:
1. https://developers.facebook.com/x/apps/662194763843967/settings/
Add your dome at App Domains in app settings
see don't use http://
suppose your domain is
http://localhost/abhinav/
then write localhost/abhinav/
click on add platform
let say its a web app
write your full site url at website text-box
Site URL : http://localhost/abhinav/
Below is the reference image where you can see what should you place at App Domains
http://i.stack.imgur.com/qZVkk.png\
So,there is some bug in Facebook and its APIs-
There is currently a bug which will prevent Facebook Login for Windows Phone
from working if you have any entries in
the "Valid OAuth redirect URIs" field in the Advanced section of your app settings.
This can be worked around by adding "https://m.facebook.com/dialog/return/ms"
in this field.
Try different links this one worked for me
"http://www.facebook.com/"

Issues using MobileServiceClient and SingleSignOn authentication

So I was just messing around with Azure and decided to look at doing some authentication in a simple Windows 8.1 Xaml based application. I was following the steps outlined in this document.
I Currently setup MobileServices, added an application to the Microsoft Store portal, and also configured the Live Services as outlined in the above link.
Where I am having issues, is when trying to use the Microsoft Account auth SingleSignOn. What's happening is that if I connect using this code:
var client = new MobileServiceClient(MobileAppUrl, MobileAppKey);
var user = await client.LoginAsync(
MobileServiceAuthenticationProvider.MicrosoftAccount, false);
then I get the correct dialog asking for an email and password. When I type it in, it authenticates fine, and works as expected. The problem is when I set the useSingeSignOn flag from false to true, I get the dialog, it asks for permission, and then it gives the following error:
We can't connect to the service you need right now. Check your network connection or try this again later.
Then will then cause an exception when I exit the dialog:
System.IO.FileNotFoundException: The specified protocol is unknown. (Exception from HRESULT: 0x800C000D)":null
I have quadruple checked my azure settings, and they are all correct, as far as I can tell. It's driving me nuts! I have Google and Googled and Googled and found nothing. So then I Binged (doesn't sound as good as Googled), with the same results.
Is there some super secret server setting I possibly missed? Any help/guidance would greatly be appreciated!
Turns out that I just needed to use a different style of signing on. I had to login using the Live SDK, then use the authentication token from that into a different overload of LoginAsync. Now it all works.

C# FaceBook error, Error Message: next is not owned by the application

This is a one page site I'm using to understand FB. I'm trying to get FB Connect to work.
I've tried several tutorials, two different domains, and tweaked the app settings on FB. All I seem to be able to get is the above error message.
I've read several answers on this site but my FB app setting don't match the any of the answers.
Thanks!
use should use Facebook rest api.And make sure that you have registered your website at facebook to connect, and you should have ApplicationKey and SecretKey.
and to connect facebook
<fb:login-button onlogin="window.location.reload()"></fb:login-button>
Then for access permission
Collapse | Copy Code
<fb:prompt-permission perms="email"> allow mail permission</fb:prompt-permission>
Add reference facebook api in your project.
ConnectSession connectSession = new ConnectSession
(ConnectAuthentication.ApiKey,ConnectAuthentication.SecretKey);
if(connectSession.IsConnected==true)//you sucessfully connected

Categories