溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

facebook 相關(guān)

發(fā)布時(shí)間:2020-07-21 16:32:48 來源:網(wǎng)絡(luò) 閱讀:327 作者:zql5666641 欄目:開發(fā)技術(shù)

/*

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

        }

    }];

}


*/


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI