您好,登錄后才能下訂單哦!
/*
- (IBAction)facebookSignUp:(UIButton *)sender
{
// [self facebook];
// return;
_accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = MNZFaceBookAppId;
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];
[_accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
^(BOOL granted, NSError *e) {
if (granted)
{
NSArray *accounts = [_accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with single sign on
_facebookAccount = [accounts lastObject];
ACAccountCredential *facebookCredential = [_facebookAccount credential];
NSString *accessToken = [facebookCredential oauthToken];
NSLog(@"Facebook Access Token: %@", accessToken);
NSLog(@"facebook account =%@",_facebookAccount);
[self get];
} else
{
NSLog(@"error getting permission %@",e);
sleep(10);
NSLog(@"awake from sleep");
}
}];
}
-(void)get
{
NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:requestURL parameters:nil];
request.account = _facebookAccount;
[request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
if(!error)
{
NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"Dictionary contains: %@", list );
NSString *userProfilePicUrl = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large",list[@"id"]];
NSLog(@"userProfilePicUrl -->%@",userProfilePicUrl);
if([list objectForKey:@"error"]!=nil)
{
[self attemptRenewCredentials];
}
dispatch_async(dispatch_get_main_queue(),^{
});
}
else
{
//handle error gracefully
NSLog(@"error from get%@",error);
//attempt to revalidate credentials
}
}];
}
-(void)accountChanged:(NSNotification *)notification
{
[self attemptRenewCredentials];
}
-(void)attemptRenewCredentials
{
[_accountStore renewCredentialsForAccount:(ACAccount *)_facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error){
if(!error)
{
switch (renewResult) {
case ACAccountCredentialRenewResultRenewed:
NSLog(@"Good to go");
[self get];
break;
case ACAccountCredentialRenewResultRejected:
NSLog(@"User declined permission");
break;
case ACAccountCredentialRenewResultFailed:
NSLog(@"non-user-initiated cancel, you may attempt to retry");
break;
default:
break;
}
}
else{
//handle error gracefully
NSLog(@"error from renew credentials%@",error);
}
}];
}
*/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。