facebook 相关

发布时间:2020-07-21 16:32:48 作者:zql5666641
来源:网络 阅读:329

/*

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

        }

    }];

}


*/


推荐阅读:
  1. Android 接入Facebook分享功能
  2. facebook为什么选择php开发

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

facebook ce ceb

上一篇:微信小程序单选框如何自定义赋值

下一篇:JSON.stringify()的详细解析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》