首页 > 代码库 > facebook 相关

facebook 相关

/*

- (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 相关