Войдите в Facebook, используя FBGraph
Я новичок в разработке iOS. Я хочу подключиться к Facebook из моего приложения для iPhone. Я последовал заFBGraph API чтобы увидеть, как мы можем использовать Facebook в нашем приложении, например:
Печатает информацию о пользователе, который вошел в систему:
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@"me" withGetVars:nil];
NSLog(@"getMeButtonPressed: %@", fb_graph_response.htmlResponse);
или список друзей:
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@"me/friends" withGetVars:nil];
NSLog(@"getMeFriendsButtonPressed: %@", fb_graph_response.htmlResponse);
А этоdoGraphGet
метод вFbGraph.m
:
- (FbGraphResponse *)doGraphGet:(NSString *)action withGetVars:(NSDictionary *)get_vars {
NSString *url_string = [NSString stringWithFormat:@"https://graph.facebook.com/%@?", action];
//tack on any get vars we have...
if ( (get_vars != nil) && ([get_vars count] > 0) ) {
NSEnumerator *enumerator = [get_vars keyEnumerator];
NSString *key;
NSString *value;
while ((key = (NSString *)[enumerator nextObject])) {
value = (NSString *)[get_vars objectForKey:key];
url_string = [NSString stringWithFormat:@"%@%@=%@&", url_string, key, value];
}//end while
}//end if
if (accessToken != nil) {
//now that any variables have been appended, let's attach the access token....
url_string = [NSString stringWithFormat:@"%@access_token=%@", url_string, self.accessToken];
}
Сначала нам нужно войти в Facebook, как показано:
Я думаю, что он использует этот код в FbGraph.m (используяUIWebView
) :
self.redirectUri = @"http://www.facebook.com/connect/login_success.html";
- (void)authenticateUserWithCallbackObject:(id)anObject andSelector:(SEL)selector andExtendedPermissions:(NSString *)extended_permissions andSuperView:(UIView *)super_view {
self.callbackObject = anObject;
self.callbackSelector = selector;
NSString *url_string = [NSString stringWithFormat:@"https://graph.facebook.com/oauth/authorize?client_id=%@&redirect_uri=%@&scope=%@&type=user_agent&display=touch", facebookClientID, redirectUri, extended_permissions];
NSURL *url = [NSURL URLWithString:url_string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
CGRect webFrame = [super_view frame];
webFrame.origin.y = 0;
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:webFrame];
[aWebView setDelegate:self];
self.webView = aWebView;
[aWebView release];
[webView loadRequest:request];
[super_view addSubview:webView];
}
Мой вопрос о возможности. Могу ли я иметь механизм, который получит электронную почту и пароль от пользователя, а затем войдет в систему (как другие методы, например, печать в консоли, что аутентификация не прошла или успешный вход в систему)?