ios - Login facebook right in app with Embedded WebView Login Dialog -
i read facebook docs , find ways login facebook. how login embedded webview login dialog fb sdk 3.5.x
it may usefull , few delegate methods of facebook shown below
- (bool)application:(uiapplication *)application openurl:(nsurl *)url sourceapplication:(nsstring *)sourceapplication annotation:(id)annotation { return [facebook handleopenurl:url]; } - (void)applicationdidbecomeactive:(uiapplication *)application { // although sdk attempts refresh access tokens when makes api calls, // it's practice refresh access token when app becomes active. // gives apps seldom make api calls higher chance of having non expired // access token. [[self facebook] extendaccesstokenifneeded]; } - (bool)application:(uiapplication *)application handleopenurl:(nsurl *)url { nslog(@"url->%@",url); return [self.facebook handleopenurl:url]; } - (bool)isfbloggedin { return [facebook issessionvalid]; } - (void)login { if (![facebook issessionvalid]) { [facebook authorize:[[nsarray alloc] initwithobjects:@"offline_access", nil]]; } else { [facebook logout]; [facebook authorize:[[nsarray alloc] initwithobjects:@"offline_access", nil]]; } } - (void)fetchfbfriends { [facebook requestwithgraphpath:@"me/friends" anddelegate:self]; } -(void)fetchfbdetails { [facebook requestwithgraphpath:@"me" anddelegate:self]; } - (void)storeauthdata:(nsstring *)accesstoken expiresat:(nsdate *)expiresat { nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; [defaults setobject:accesstoken forkey:@"fbaccesstokenkey"]; [defaults setobject:expiresat forkey:@"fbexpirationdatekey"]; [defaults synchronize]; } nsstring *strres = [nsstring stringwithcontentsofurl:[nsurl urlwithstring:[nsstring stringwithformat:@"https://graph.facebook.com/me?fields=name,username,email,gender,birthday,hometown,picture&access_token=%@",facebook.accesstoken]] usedencoding:&encoding error:&error]; nsmutabledictionary *dirfbdetails = [[nsmutabledictionary alloc] initwithdictionary:[strres jsonvalue]]; -(void)fbdidextendtoken:(nsstring *)accesstoken expiresat:(nsdate *)expiresat { nslog(@"token extended"); [self storeauthdata:accesstoken expiresat:expiresat]; } -(void)dofacebooklogin { [self.facebook authorize:[nsarray arraywithobjects:@"friends_birthday",@"user_birthday",@"email",@"publish_stream",nil]]; } #pragma mark - fbrequestdelegate methods - (void)request:(fbrequest *)request didreceiveresponse:(nsurlresponse *)response { } - (void)request:(fbrequest *)request didload:(id)result { } - (void)request:(fbrequest *)request didfailwitherror:(nserror *)error { nslog(@"err message: %@", [[error userinfo] objectforkey:@"error_msg"]); nslog(@"err code: %d", [error code]); }
Comments
Post a Comment