首页 > 其他 > 详细

facebook 相关

时间:2014-12-25 18:42:55      阅读:275      评论:0      收藏:0      [点我收藏+]

/*

- (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);

        }

    }];

}


*/


facebook 相关

原文:http://zqlicoder1314.blog.51cto.com/3014999/1595943

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!