0

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.

J.B
  • 1,642
  • 2
  • 15
  • 33
  • You have to create app in Facebook Developer dashboard then integrate your Windows 8 app with Facebook app. Now when user signs in via facebook then after successful sign in you will get access token which is unique for all the users. So you can save that access token then user doesn't have to login more time. Currently Facebook has stopped plenty APIs so Facebook C# SDK also is giving less methods – Farhan Ghumra Mar 26 '13 at 10:23
  • I see, I have already done most of what you mentioned. I have created an app on Facebook and used its App ID to get a response from Facebook. Are you saying that if I save the access token the user gets in isolated storage after their first login, I will be able to use this on successive app sessions without problem, or will it change? – J.B Mar 26 '13 at 16:23
  • Token is expired when user changes password. Then also I suggest you to check Facebook developer site to know when token expires. – Farhan Ghumra Mar 28 '13 at 08:29
  • Thank you very much, I have applied as that you have said and it seems to make sense and work. My second point can wait for another time as I am not quite ready to implement it. If you put all that you have said as an answer I will happily mark it as correct. – J.B Mar 29 '13 at 11:33

1 Answers1

1

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

Community
  • 1
  • 1
Farhan Ghumra
  • 15,180
  • 6
  • 50
  • 115