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.
Related
I am just starting out with a windows azure mobile services .net backend, and am running into so many headaches as a new programmer. I have gone into my azure mobile services account and downloaded the todoitems demo app (c# for .net backend). I then followed the tutorials regarding adding facebook authentication, but I am absolutely not pleased by this method, as it shuts down the app for a few seconds. As such, I set out determined to create a custom authentication login page which ties to my mobile backend.
I found this article and thought, "Great!" only to realize that I had no clue how to catch a user created account from a textbox and to pass it along to the public class RegistrationRequest. The example at the end of the link shows how to connect to a local machine - but I want it to connect to my actual database at the following location: https://mycustomapp.azure-mobile.net, return a token, and continueon.
What is frustrating is that I am able to obtain a facebook authentication token, as well as user information. BUT, I have no idea how to generate a windows azure mobile auth token so that the client may write/retrieve data from my azure table.
Essentially my question is this - using the above link, how in the world may I take a user's username and password from a textbox, run it through the RegistrationRequest, and not have to pop advil on this? Do I need to pass my facebook token? I assume not?
I am also not using a facebook SDK or anything like that - simply put, I am using the above site's code trying to get an auth token from my azure mobile services, despite having one from facebook already, to authenticate a user against my azure mobile services data table.
If you already have a FB token, the easiest way to login to your mobile service is by using the FB token, then you don't need to make a custom UI/etc.
This can be done by calling
var token = new JObject();
token.Add("access_token", "access_token_value");
await client.LoginAsync(MobileServiceAuthenticationProvider.Facebook, token);
see: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-windows-dotnet-how-to-use-client-library/#authentication, Client Flow for more
if you want to login to your service with a Facebook account, you do not need to implement a custom authentication and to capture user name and password in your own textbox controls.
You should be able to use MobileServiceClient.LoginAsync() and pass as parameters the provider that you want to use. Check this article fro more information.
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.
I'm currently writing a facebook app for windows phone, and there is something I just didn't find how to do.
Since display=touch currently doesn't work on windows phone, I am forced to use display=popup to get a token and the user's agreement for my app.
This popup mode really isn't fit for mobile apps, so I would like the user to be able to check a box saying "I would like the app to remember my login and password and connect me automatically".
However, when I have the user's login and password, I don't know how to use the OAuth API to effectively login the user without him having to click anything. Is there a way to do that ? Or do I have to wait for the user to choose "Remember me" on the Facebook login page ?
I hope that was clear enough.
Facebook doesn't have a (public) API for taking a users email address and password and returning an access token. The closest thing you can do is customize the HTML that gets returned with JavaScript. I have an example of this on my github.
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/
Is there any good tutorial how to make simple console facebook appplication which connect to facebook and get list of friends, user photos, status or something. I look at facebook examples of facebook SDK but if i want to authorize on facebook i must execute FacebookService.ConnectToFacebook method which show login window. But i want show my own login window. Or just store login and password in sql server and time to time get some information about users. Is it real?
Check out the tutorial and examples here.
It should have all the functions that you need and is fairly easy to implement. Trust me, you'll spend hours going elsewhere to figure it out.
As for custom login windows I recommend that you don't do that. People trust Facebook and don't want to give you their personal info, that's actually a part of your agreement with Facebook.
What you can do however is ask for offline access permission and store the token for future use. This way if you know who the user is on your end then you can make calls to the API without having to log them into Facebook again.
Facebook requires that users login with them and Facebook will send you back a token which you can use. This is prevent applications "stealing" usernames & passwords, which you could do with your login dialog and also allows users to stop applications in future from accessing their account even if they have logged in previously.
No way round that unfortunately, unless you going to build something that doesn't use the API - for example, a tool which loads a browser in a background, and automates the login as if the user did it. That would lead to pain and suffering though.