14
我與電子郵件的權限打開Facebook的會議,像這樣:如何在iOS上使用Facebook SDK 3.1獲取用戶的電子郵件?
- (void)facebookOpenSession {
NSArray *permissions = @[@"email"];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
然後會話狀態的重要片斷改變的樣子:
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error {
switch (state) {
case FBSessionStateOpen: {
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
//error
} else {
self.myFirstNameLabel.text = user.first_name;
self.myLastNameLabel.text = user.last_name;
// self.myEmailLabel.text = @"";
}
}];
}
...
如何確實提取了用戶的電子郵件?它是否在提供的變量之一中,還是必須在完成處理程序中再次調用?
在此先感謝!
是的,這沒有竅門! – user1601540