Is it possible to obtain Facebook API access token server-side? - c#

I am trying to integrate a Facebook news feed into a website using Facebook C# SDK https://github.com/facebook-csharp-sdk
var client = new FacebookClient("token");
dynamic me = client.Get("username/feed");
I have not been able to find any examples of generating an access token at runtime. All examples seem to be targeted at client apps where a used would be required to authorise the application.
Based on what I've seen so far, there used to be a way to generate a permanent access token (using offline_access permission), but as of 2nd May 2012 that approach is deprecated.
At the moment, I am not sure this is even a supported scenario.
Is it possible to get Facebook news feed entirely using server-side code with no user involvement?
EDIT: Looks like there might be a way: https://developers.facebook.com/roadmap/offline-access-removal/#extend_token
Will try later and report back.

no, you can't do anything with username/password. the user has to enter these into facebook's login ui and click the button to agree to letting your code do whatever it's asking to do.

Related

Google - C# WinFormsApp - Auth

I have a question,
Is it possible to use Google user accounts for authentication in WinFormsAPP?
I need to write an application in C# Winforms that reads user-specific data from a database.
Is there an easy way to authenticate using Google?
I might be able to store a list of valid Google users in my database, or maybe I can even define a list of valid application users in Google?
Is there perhaps already a sample project for this case somewhere? I actually can't believe that I am the first developer with such a requirement...
I am grateful for any help or suggestion!
Have a look at:
Integrating "Sign In With Google" Functionality To An Application
Login using Google OAuth 2.0 with C#

C# - Check if user is logged in Facebook

I'm working on a Windows Phone Silverlight app and I want to make a simple login via Facebook(browser). Is there a way to check if the user is logged in Facebook? I redirect the user to Facebook page with this statement:
Launcher.LaunchUriAsync(new Uri("http://www.facebook.com"));
I don't know if you are using the windows SDK for facebook
(https://github.com/Microsoft/winsdkfb) but it is a third party sdk approved by Facebook.
Before using that SDK you should set up the Facebook developer page for your app. (https://developers.facebook.com/docs/apis-and-sdks)
I hope that helps.
Here is a WPF example that uses the WebBrowser class to get a token: Facebook OAuth in WPF & C# Example
Obviously the WPF related things might differ a bit, but it should at least point you to getting the info you need out of the process. As far as checking whether the user is logged in, I pretty much just checked whether the token is valid by making some http request that uses it and seeing whether it was successful (used a REST client for that).
There was a way to directly check token validity via the Facebook APIs but that was deprecated last I checked.

Getting my own data from facebook using C# WITHOUT an application

I've been googling for a couple of days, and I could not find any clue how to achieve that:
I have a desktop application(C#) in which I'd like to be able to login to my facebook profile, and pull some data from it(e.g. profile information, wall posts, likes on my posts, etc.)
Note that I DO NOT want to develop a facebook application, I simply would like to access my own user data.
As far as I see, the Graph API was designed to develop FB apps, and Graph API calls always need an access token, but I do not have token, since I do not use any Facebook application.
By now, the only way I see for that is to add a web browser component to my application, and login to the facebook through it, but it's quite inconvenient to process the pure HTML, and, since the HTML itself can change at any time, the maintenance of the application would be a horror.
So I'd like to find some way to pull data from facebook in JSON format, like the Graph API, but without having a Facebook application.
Thanks in advance for the answers.
It's not possible to access the data without a facebook application.
As you wrote, you need an access token for most graph requests, and in order to have an access token you need an application.
More than that, from what you wrote you'll need extra permissions which are not granted by default (for the user photos, wall posts, likes and so on).
Facebook can't just give you the info you see, the user has to grant a specific application the right to access their data, and because of that you must have a facebook app.
I don't see what the problem is though, just create a facebook app, it's not that complicated.

Proper way to get the Token Key for Facebook Graph API

I normally use a dirty method to get my Facebook Graph API token key in applications that fetches facebook data. I download the Graph API example page at graph dot facebook dot com then I locate the token key in the page. (The account is already connected)
Now, I need to program (for someone else) a commercial application that uses Graph API and I'm afraid such an hacky way could become non-functional if Facebook website changes.
Is there a static URL more common than the example page where the Graph API token_key resides, or do you think my method will be safe for a long time?
[Edit]
Just to comment my question, and the answer to my question:
I was trying to build a desktop application fetching data on Facebook using only Graph Explorer and the Graph API example page instead of doing the web request in the answer. I didn't want to have a desktop application that depends on a Facebook App so that's why I was always asking the user to connect via two text boxes (which is against Facebook t&c) then I was downloading the Graph API examples page to get the proper token.
But Graph Explorer and its examples are using a 'Facebook App' too. So it's not clear if the access_token are going to be valid for a long time or not: It's not a good practice.
The answer is: Redirecting a user to an authentification page then fetching an access token is safer, easy to handle and a lot more stable than connecting a user via text boxes and several WebBrowsers navigation.
You can get an application access token to query public data on Facebook from this URL:
https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={yourappid}&client_secret={yourappscret}
You need to create an application on Facebook and pass it's ID and secret key.
More information on: http://developers.facebook.com/docs/authentication/applications/

Facebook website integration - what's actually possible in terms of custom website features

I know there are a lot of questions out there for facebook integration, and a lot can be read of off developers.facebook.com - which I did. But I'm missing some clear and precise answers as to what I can actually do in terms of my project.
So I know I can connect my website with a facebook account, and as far as I can read it's possible to "attach" a facebook account to a user in my own custom user-database. Correct?
I'm looking primarily to be able to do this, but not necessarily require the user to have a facebook account to use my app. And as far as I've understood, this is possible too.
To provide context I'm building a specialized photo sharing app.
Where it gets iffy for me, is if I choose to have the ability to comment on a picture on my app. I know there is the social plugin "Comments" for facebook, but how exactly would this work? It would store the comments in facebook would it not? And if a user with no facebook account registers at my site, he won't be able to use the comment feature? Can he even see the comments? Is it at all possible 'hook up' facebook comments to a custom comment-feature on my site? So the user without facebook can still comment?
And this whole integration - would it require the user to 'install' a facebook app (mine) on facebook?
"So I know I can connect my website with a facebook account, and as far as I can read it's possible to "attach" a facebook account to a user in my own custom user-database. Correct?"
Correct, you use the userid that Facebook provides to identify the user.
"I'm looking primarily to be able to do this, but not necessarily require the user to have a facebook account to use my app. And as far as I've understood, this is possible too."
Yes, you just need to built the extra functionality into your app (allow for registrations coming from FB or a regular form from your website). You might want to have a look at Facebook's registration plugin.
"The plugin also allows users who do not have a Facebook account, or do not wish to sign up for your site using Facebook to use the same form as those who are connecting with Facebook. This eliminates the need to provide two separate login experiences."
"I know there is the social plugin "Comments" for facebook, but how exactly would this work? It would store the comments in facebook would it not?"
Yes, it stores them on FB, but you can access them and replicate them into your database via the Graph API. Read this for details.
"And if a user with no facebook account registers at my site, he won't be able to use the comment feature? Can he even see the comments? Is it at all possible 'hook up' facebook comments to a custom comment-feature on my site? So the user without facebook can still comment?"
The comments feature will not be tied to your site's registration, since it does a separate auth check. Unfortunately, the comment plugin does not support anonymous comments, or pushing comments into it from another app, so a user will have to have an account in Facebook, Yahoo, AOL or Hotmail to post a comment. But all users will be able to see the comments, regardless of account status (you can control that from your code of course - e.g. hide the comment plugin for a user group).
Besides FB's plugin you can have a look at other solutions like Disqus (http://disqus.com/), which supports multiple login sources AND allows for anonymous comments if you want.

Categories

Resources