通过Facebook和服务器端验证的ios身份验证

时间:2012-03-10 03:46:33

标签: iphone facebook oauth

我的iOs应用程序使用facebook-sdk对Facebook用户进行身份验证。

现在应用程序连接到服务器并且必须确认用户身份。哪种推荐方式? 可能iphone必须向服务器发送某种令牌,服务器必须通过facebook api call确认它

你有这些文档的链接吗?

1 个答案:

答案 0 :(得分:0)

你好,你想在你的ios应用程序中使用Facebook登录我已经使用了这个代码来检查它 首先在你的应用程序中获取Web视图并与Nib文件建立连接。然后输入你的facebook Appl

- (void)viewDidLoad
{
[super viewDidLoad];

 NSString *client_id = @"Enter your Application ";

NSString *redirect_uri = @"http://www.facebook.com/connect/login_success.html";

NSString *url_string = [NSString stringWithFormat:@"https://graph.facebook.com/oauth/authorize?client_id=%@&redirect_uri=%@&type=user_agent&display=touch", client_id, redirect_uri];

NSURL *url = [NSURL URLWithString:url_string];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[self.webView loadRequest:request];

}
 -(IBAction)getText:(id)sender{

 NSLog(@"%@",[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"]);
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView {



NSString *url_string = [((_webView.request).URL) absoluteString];
 NSLog(@"%@",url_string);

NSRange access_token_range = [url_string rangeOfString:@"access_token="];

//coolio, we have a token, now let's parse it out....
if (access_token_range.length > 0) {

    int from_index = access_token_range.location + access_token_range.length;
    NSString *access_token = [url_string substringFromIndex:from_index];

    NSLog(@"access_token:  %@", access_token);
   htmldata=[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];
    NSLog(@"%@",htmldata);
    NSLog(@"%@",url_string);
    NSArray *arr1=[htmldata componentsSeparatedByString:@"<title>"];
    NSString *data=[arr1 objectAtIndex:1];
    NSArray *arr2=[data componentsSeparatedByString:@"</title>"];

    value=[[NSString alloc]initWithString:[arr2 objectAtIndex:0]];

    NSLog(@"%@",value);
    if([value isEqualToString:@"Success"])
    {
        MainScreenController *C = [[MainScreenController alloc]init];
        [self.navigationController pushViewController:C animated:YES];
        [C release]; 
}
}
}

感谢