Integrating Facebook throughout a C# Windows Store app - c#

The C# Facebook SDK host on github allows Windows Store apps to login to their account via the app and post e.g. statuses or app related content through the app, however there are still some concepts that I don't understand.
Firstly, is it only possible to perform facebook related tasks after I have logged in for the current session. Can I not login in once (say, when I first download an app) and then have the app retain my settings. Then, whenever I want to post some content via my app and can just do it straight away, instead of having to sign in again (in the same or another session)
I was hoping that in my app I would be able to login in via an option in the settings charm which would navigate to my HomePage.xaml, and then I would be able to save that login state for multiple sessions. Currently I have this first bit running (though not completely, I can login but that's it right now), but how would I/can I automatically post content in future sessions without having to log in again?
Secondly, many apps that integrate with Facebook apps, that allow the user to post data stored in their local app or web user account via the Facebook app counterpart. How is this performed?
Say I have a class MyDataClass which contains properties DataTitle, DataItem1 and DataItem2. I would want to be able to send this to my wall, and have it display as an ordinary post (examples for this sort of functionality include things like ask.fm and formspring.) Would I then even be able to store this data via my Facebook app, and be able to send it to the users friends should they wish?
I would appreciate it if someone could explain whether these things to me. I've been search for a couple of days now and haven't answered these bigger questions.

Facebook C# SDK can be used via NuGet or you can get library from GitHub. When any user logs in via Facebook, the login result returns "Access Token". It is unique among all the Facebook users. You can save that access token in individual user's LocalSetting. Local setting documentation can be found here. Local setting can be used in this way.
//create instance of local settings
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a setting
localSettings.Values["FB_Access_Token"] = "THIS_IS_DUMMY_ACCESS_TOKEN";
// Read data from a setting
var objFbAccessToken = localSettings.Values["FB_Access_Token"];
if (objFbAccessToken == null)
{
// No data
// Do relogin of Facebook and save new facebook token
}
else
{
// Access user's Facebook data with help of Facebook C# SDK and Access Token
}
// Delete a setting
localSettings.Values.Remove("objFbAccessToken");
See this for extending access token.
Get long live access token from Facebook

Related

Office 365 App Only Auth MVC c#

I have currently implemented the code into my app from https://github.com/mattleib/o365api-as-apponly-webapp
It all works when clicking sign up, Auth's the account properly and returns to the same Page and allows me to load the calendar events.
My issue is that i need this to be persistent across the entire app as my aim is to do the following.
Administrator on initial login and or app start up, Auth's the app to Office 365.
When a user logs in they have a link to a page that will display the calendar that is configured for the page, a Resource.
Im assuming i need to setup a token cache, but not sure where from the above code sample, the token is generated and returned. I think it is stored in this variable on postback, Request.Form["id_token"] but unsure on how to store this in a cache/make it available for the entire application.
I have seen some examples that use Session Token Caches but if i am correct, this will require re auth to offcie 365 for each and every user and not be an app wide auth.
Ive tried searching for some samples or any pointers but cant seem to find any.
Anyone able to point me in the right direction

c# retrieve facebook page insights with console application

I need to write a program that will retrieve facebook insights from a page I'm the administrator of. I have to use a console app because there are other things that I must do later with the data. My problem is with logging in automatically. I created a facebook application but after doing some research I saw that for reading a facebook page insights I must first login to obtain an access token, which would allow me to obtain a manage_page permission.
So my question is how do I obtain user access token with the console app in C#?
var fb = new FacebookClient();
but then what?
The best way to learn how to code an Insights application is to use the Getting Started wizard. You can find Getting Started session in https://developers.facebook.com/apps/[app_id]/marketing-api/
Basically you can pick metrics and the wizard will generate a working code for you. (It is only generating Java code for now)
Also if you don't really wants to code, you may try the new product we just released called Facebook Ads Manager for Excel. It allows you to download Insights data into Excel directly. More info:
https://www.facebook.com/business/m/facebook-ads-manager-for-excel

Retrieve hidden playlists from my own account using YouTube API without requesting password from client (.NET/C#)

I am trying to find a way to retrieve my own private playlists from my own personal YouTube account via a server side web app built in ASP.NET (C#). Based on the research that I have done, the consensus seems to be that my app needs to authenticate against my account with Oauth 2.0. I want my website to show a list of videos from a few playlists that I have set as hidden, and I want the list to show on a public page. For this reason, I obviously do not want to enter in my youtube account details every time that I browse the page.
I have looked and looked and there does not seem to be any clear way to do this. Some people have suggested going through the Oauth 2.0 authentication flow once, then use the code that it returns in the redirect URL to generate a refresh token, and use that token in your application; another suggestion I have read is to use an API service account. There does not seem to be any working example code available anywhere.
Has anyone had to do this same thing and have you been successful setting it up? Google's own API client library documentation is abysmal, especially for the .NET libraries.
If the playlists are hidden you won't be able to access them without logging in.
If the playlists are public you can always query for them through the YouTube API without having to pass your credentials.

Get user's session outside of Facebook Application from a windows service or desktop app

I've a flash facebook application, i can take the session info from flash client and send the session information to server.
I need to check if the user connected to the server via facebook application or not. That's why i need to get the user's session from facebook page directly by my server.
How can i do it? I use C# for all database and communication system. Flash interface does only application responsibilities.
Thanks.
You cannot do this. You must use Facebook OAuth authentication. If you want to use the user's session after they are not using your application then you should ask for the "offline_access" extended permission. If you have that permisssion, you will get an access token that never expires. Then you can save that access token in your database and use it from you windows service. Check out the Facebook C# SDK to make all this stuff a lot easier.

automatic login to facebook

I'm creating a desktop application in C#.
one of the things that this application should do is to publish things to the status of the user in facebook (like: "dave just won 3 gold medals" ). this should happen whether the user is logged in now to facebook or not. I want the user to give me all the needed permissions once and then everything would happen automatically (I would save whatever is needed on my DB).
I tried using facebook developer toolkit 2.0 for .net but didn't see anything there that could help me.
ANY help would be appreciated.
For you question:
you need to use the Facebook Connect API
there is a Feature called offline_access - its an extended permission.
In FB Connect you need to toggle the correct popup :
The workflow will be like that:
User uses FB Connect to confirm the fact he wants to connect your app to his facebook account.
You trigger the popup.
You can then call all calls on his permission even if he is offline (or not using facebook connect)
For the sake of understanding: FB Connect is meant that way that you can easily log the user into his app and do everything on his behalf. offline_access is actually meant for cronjob work.
Iv'e got some answers here. I think it answers other questions I saw in the web lately:
My answer is related to desktop applications that works outside of facebook (facebook connect).
+ I'm using the facebook developer toolkit 2.1:
Here is how to get the special permission, needed to for offline access. and how to get the session key:
facebook.Components.FacebookService FS = new facebook.Components.FacebookService();
FS.GetExtendedPermission(facebook.Types.Enums.Extended_Permissions.offline_access);
The second line will force you to login and afterwards would ask for the permission after the user choose to grant the permission, you are given in the post URL - the fb_si_session_key. BUT the toolkit developers didn't do enough to bring it to you :-(
So you have few options. the simple one is to do:
FS.Logoff();
FS.ConnectToFacebook();
What will happen is that you'll see the login screen for a second and before youll be able to click anything it would vanish. but this time you'll have the right session key. you can get it like that:
string myPermanentSessionKey = FS.API.SessionKey;
If you dont want to show that annoying screen again you have few options, all of them are related to changing the source files of the toolkit. I'm not gonna get into it here, but just tell you a simple option: in the facebookconnect() function I changed it to receive a parameter (isShow) when I send true to it, it behaves normal, when I send false to it - it skips on the formLogin.ShowDialog();
It's working.

Categories