Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Extract Facebook Information from ACS using iOS Windows Azure Toolkit
NSString * const ACSNamespace = @"your ACS namespace";
NSString * const ACSRealm = @"your relying party realm";
NSString * const NameIdentifierClaim = @"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";
NSString * const AccessTokenClaim = @"http://www.facebook.com/claims/AccessToken";
- (IBAction)login:(id)sender
{
self.loginButton.hidden = YES;
WACloudAccessControlClient *acsClient = [WACloudAccessControlClient accessControlClientForNamespace:ACSNamespace realm:ACSRealm];
[acsClient showInViewController:self allowsClose:NO withCompletionHandler:^(BOOL authenticated) {
if (!authenticated) {
NSLog(@"Error authenticating");
self.loginButton.hidden = NO;
} else {
_token = [WACloudAccessControlClient sharedToken];
self.friendsButton.hidden = NO;
}
}];
}
- (IBAction)friends:(id)sender
{
// Get claims
NSString *fbuserId = [[_token claims] objectForKey:NameIdentifierClaim];
NSString *oauthToken = [[_token claims] objectForKey:AccessTokenClaim];
// Get my friends
NSError *error = NULL;
NSString *graphURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/friends?access_token=%@",fbuserId,oauthToken];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:graphURL]];
NSURLResponse *response = NULL;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *friendsList = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"id" options:0 error:&error];
NSUInteger friendCount = [regex numberOfMatchesInString:friendsList options:0 range:NSMakeRange(0, [friendsList length])];
[friendsList release];
self.friendLabel.text = [NSString stringWithFormat:@"%d friends", friendCount];
self.friendLabel.hidden = NO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment