简体   繁体   中英

Authentication Facebook C# SDK

I have a website where i have a event module, where the users can maintain their own events.

At the same time i have a Facebook Page(not app) and i would really like to create/update/delete the events from my website directly to Facebook.

I have the following working:

        FacebookClient clientApp = new FacebookClient(token);
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("name", currentEvent.HeadLine);
        DateTime startTime = DateTime.Now;
        DateTime endTime = DateTime.Now.AddDays(1);
        parameters.Add("start_time", currentEvent.StartDateTime);
        parameters.Add("end_time", currentEvent.EndDateTime);
        parameters.Add("location", currentEvent.Location);
        parameters.Add("description", currentEvent.Description);
        var postResult = (IDictionary<string, object>)currentClient.Post("pageid/events", parameters);

the accesstoken used is from my facebook login, so if that expires the system fails.

Any other way or can i get a newer expiring accesstoken.

Regards Keld

regards Keld

You have two options, one is to request the permission offline access from Facebook when you obtain the token. This gives you a token that never expires (unless the user explicitly removes access for your app.

The second way is to handle exceptions from the callback of the method. In the handling code you detect a token expired exception and redirect users to the appropriate login page to get a new token. You can then re-try the event update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM