I do not know any APIs, but this does not mean that you cannot get the same functionality as on sites. However, without an API, your code is prone to potential breakdowns whenever Facebook or Google updates their web applications.
Facebook
For facebook, you can clear the URL https://www.facebook.com/settings?tab=security§ion=sessions&t . Also explore the URL https://www.facebook.com/ajax/settings/security/sessions/stop.php?__a=1 , which is the URL that is available in the background when you click on the "End Activity" link.
GMail
Google seems a little more complicated, but if you are scripting https://mail.google.com/mail/h/ (plain-html interface), find and follow the Details link below, you can automatically register sessions too.
source share