Post image to facebook from desktop application - facebook

I have this desktop windows app written in C#
The user can post an image to his wall from the app. I have already created the Facebook app. In the previous version the win app would upload the image to my web site then the user was directed to https://www.facebook.com/dialog/oauth/ (via Process.Start(…) that would open the default browser) with my Facebook apppid and a redirect_uri and after authentication and obtaining an access_token the post image dialog would open. It all worked fine.
However, my question is if I could do these stages without a web site of my own, directly from c#.
I have seen plenty of examples but most of them refer to aspx, php and javascript but after all this is a few http request so I think it should be possible.
I think the main problem is how to get an access_token if there is no web page that the user is directed to after login.
I have seen an example using the webbrowser control but it wasn't very clear. And also, if possible I rather that the user would login using their default browser where they are most likely already logged in to Facebook and don't need to enter user and password just for this.
Also, is it possible to upload an image to facebook directly from my app without putting it on some public url first.
Any help would be appreciated. Thanks

Related

Unity - How to log into Facebook without SDK?

I want to see if I can make my Unity application login to Facebook without using the Facebook SDK. Instead, I want to use the Graphs API, because the SDK does not play nice with other plugins and has lots of baggage I don't need.
I'm sending a GET request from my Unity app, which uses the API for getting auth token:
https://www.facebook.com/v15.0/dialog/oauth?
client_id={app-id}
&redirect_uri={redirect-uri}
&response_type=token
From my knowledge, this is supposed to either open the redirect URL with the auth token attached, or prompt me to sign-in/approve this app logging in. It works well pasting this request into a browser and hitting enter.
However, when sending this request via Unity, I get an HTML file as response. Opening this HTML file shows a page where Facebook tells me that Facebook does not support this browser and tells me to go download Chrome or Firefox.
Has anyone managed to get Facebook sign-in to work without the SDK? Or any idea how to avoid this error and get redirected to the page as expected?
Thanks in advance!

facebook external login not redirect back

I have a MVC5 application with external login. When I use Facebook login, after I put in my login information into facebook login page, facebook fails to direct me back to my application.
I got a white page with the following URL in Chrome's URL bar:
https://www.facebook.com/dialog/oauth?response_type=code&client_id=632877723495196&redirect_uri=http%3A%2F%2Flocalhost%2FMPOS%2Fsignin-facebook&scope=email&state=l2oJwWdkbRsgZHyr6-5lL9ZTZc-eMbRBkH73L-h1ZN_MWvWriNeEdCxuNspi4QptZAna60SQIJX4NB5AItzP6NxpDCz10m48JInWUfvQGWkgFgZhZNFIaTz6ju-kEQ-RyiObgiMOKvBougeeaSHD7CAzTrvc1Gj6XdGgGbUgyrM9d1KZUEGbqh_MdyBPg4wTFbQEiui-2GzvcIvhOVtTRC12NnhgnVyLCrrKEDFaWdU
If I use IE, I got "The website cannot display the page" error page with the following URL on the borwser's URL bar:
https://www.facebook.com/login.php?login_attempt=1&next=https%3A%2F%2Fwww.facebook.com%2Fv2.1%2Fdialog%2Foauth%3Fredirect_uri%3Dhttp%253A%252F%252Flocalhost%252FMPOS%252Fsignin-facebook%26state%3DWbWcYquZJnjvo8Db42l6goqpMUrioHL6HBVIUMu74QvqMuAjNzWizophJhNpf3NHCbw1-Dw1tsdgmv2h1f0ct1zcLJ_jlSXQ3ImCHVN_PXRkRedVB3gjTQb59-tbxPKxJQTuNhPvOKLq6aBjakP_fJDw5zXKZ55LrRzHVzEQ39Qff7WXsNJpke2BTHILHLI0I5jcWiXEgE-HeH7La19ttaL9LhrcyXP4DBiWaXuUNZc%26scope%3Demail%26response_type%3Dcode%26client_id%3D632877723495196%26ret%3Dlogin
Anyone has an answer to this problem? Thanks!
Thanks Nathan, clear cache on browser didn't help. I tried to clear cache/cookies on both IE and Chrome several times before I post the question.
The weird thing is that if I create an app under my personal facebook account and use the FacebookAppID/FacebookAppSecret for my app, the external login works fine. That's how I did all my testing.
But when I try to deploy the website I want to create the app under company's facebook account. I set up the app under the company's facebook account exactly the same way as I did when using my personal facebook account, then I got this redirect problem. If I switch back the FacebookAppID/FacebookAppSecret to the one I created under my personal account, everything works fine. That's even more puzzling.
I finally figured out the problem. I forgot to turn on "make this app and all its live features available to the general public" setting for the app I created in Facebook. So the login was only available to the developer who created the app. After I turn that setting on (it is under the Status and Review Tab), everything works fine.

Should Facebook canvas apps behave same if opened from original non-canvas site url?

This is a first time I am trying to make a facebook application/game, and I have couple of questions.
Let's say canvas url is http://mysite/first_app/ and facebook app url is https://apps.facebook.com/first_app
I wonder if visited both url-s should a functionality be the same? I mean does facebook give you more tools and freedom if navigated from https://apps.facebook.com/first_app? Or should both url-s look and do the same thing? Is it possible?
I wonder if visited both urls should a functionality be the same
Of course yes. The difference is just that one is deployed at the facebook's app center and the other at your domain.
Yes, you have more tools available in the canvas ("apps.facebook.com.."), as it will send you the user-id without any user consent. Has the user previously used your app, you will also be able to get their accesstoken and fetch more info about them.
It requires some backend code to decode the signed request parameter, which provides you this stuff.
This example is how php handles signed request:
https://developers.facebook.com/docs/facebook-login/using-login-with-games/
If you're using C#, download the Facebook C# (available through NuGet, the package from Outercurve Foundation) and use this example:
How do I parse a signed request in Facebook C# SDK?
I try to handle the user in Facebook context whenever possible. It adds trust and more tools. Although since the Facebook phone/tablet app (App Store/Google Play) doesn't support Facebook apps at all, I often optimize the app for mobile web use also. I read somewhere that over 50% of daily Facebook visists are done using the phone app, so it might be something to think into your app while developing.
UPDATE:
I can see I have misunderstood part of signed request, as commented by Shadowfax and CBroe. In my app, I use the user id from signed request but of course only when the user has already logged on to the app beforehand. My apologies.

Redirect Facebook App To External Page

I'm having issues configuring my Facebook app to behave as I want when posting information via the Feed Dialog. I've set up an app and created a link that correctly posts my content when clicked, but I can't figure out how to make the link to the app in the resulting post redirect where I want it to.
As an example, here's a post made via Instagram.
If I click on the 'via Instagram' link, I get either prompted or automatically redirected from the destination URL http://www.facebook.com/apps/application.php?id=124024574287414 to www.instagram.com.
I've seen other posts suggest you can do something similar using a JavaScript redirect from the App Canvas page, and I've got a proof of concept doing this, but since I've seen Instagram and other apps do this seemingly internally to Facebook I'm convinced it's possible to do more cleanly.
That link goes to your app's canvas URL (apps.facebook.com/something) or website URL as defined in the app settings, it can't be configured with any more granularity.
This seems that it will probably do the trick most easily: http://woobox.com/statichtml
See the redirect radio button in the image they have.

App Center - Mobile site not passing oauth code

I'm trying to set up my app for the App Center and have come across an issue on the mobile site preview.
For the main Website preview Facebook is passing the code auth token parameter in the query string as expected. I am using this to login the user and display a personalized experience as they ask for in the guidelines.
However on the Mobile Web site Facebook is not passing this parameter after authentication. The only alternative seems to be to use the Javascript SDK to automatically login the user.
I've also noticed that on the preview page the Website version links directly to my website whereas the Mobile preview links to the m.facebook.com/apps URL, though they should be set up the same.
I also have this problem, but with the very Website option, as I don't use the mobile one. As a matter of fact, I have never seen the code in the query parameters coming directly from the app center, and I have been doing this for quite a while.