嗨,我想从ACAccountStore的iOS 6中获得Facebook用户的UID
self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = @"01234567890123";
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with single sign on
self.facebookAccount = [accounts lastObject];
//i Want to get the Facebook UID and log it here
NSLog(@"facebook account =%@",self.facebookAccount);
} else {
//Fail gracefully...
NSLog(@"error getting permission %@",e);
}
}];self.facebookAccount有UID,但我无法得到它.
发布于 2013-02-20 18:33:03
我想在不使用Facebook的情况下获得UID。它可以通过以下方法完成
self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = @"01234567890123";
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with single sign on
self.facebookAccount = [accounts lastObject];
//i got the Facebook UID and logged it here (ANSWER)
NSLog(@"facebook account =%@",[self.facebookAccount valueForKeyPath:@"properties.uid"]);
} else {
//Fail gracefully...
NSLog(@"error getting permission %@",e);
}
}];发布于 2013-02-19 20:14:16
您需要调用Facebook图形API;按以下方式使用SLRequest:
NSUrl requestURL = NSUrl.FromString("https://graph.facebook.com/me");
SLRequest sl = SLRequest.Create(SLServiceKind.Facebook, SLRequestMethod.Get, requestURL, null);
sl.Account = // your ACAccount object here
sl.PerformRequest((data, response, error) => {
if (error == null) {
// success! parse response
}
else {
// handle failure
}
});这样就行了!
https://stackoverflow.com/questions/14951984
复制相似问题