问题
I implemented Facebook Graph API in my iPhone App and I successfully post it in a wall. But each time I end my application and come back it stores my credentials (in Safari I guess as a cookie). It asks my permission with my previous credentials. But at this point I want my Facebook API should prompt for a new username and password login for requesting permission. In simple I want to logout of my Facebook when i select a button in my App.
回答1:
How did you log in to facebook in the first place? If you are using facebook iOS SDK, you just basically have to call [facebook logout:self];
. Otherwise if you're implementing Graph API yourself you just need to clear out your cookies and delete your access token.
回答2:
fbGraph.accessToken = nil;
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString *domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:@"facebook"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
回答3:
when you are call the facebook button at that method last line u wil write this method [facebook logout]
回答4:
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies])
{
[cookies deleteCookie:cookie];
}
These codes are enough to implement logout functionality.
Its working perfectly on my app.
来源:https://stackoverflow.com/questions/4735905/how-to-implement-logout-functionality-for-facebook-graph-api