SLRequest -FaceBook

-(void)facebook{

    ACAccountStore *account=[[ACAccountStore alloc] init];  //本机账户数据库, 储存weibo,facebook等各种账户

    ACAccountType *accountType=[account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    NSLog(@"accountType:%@",accountType);

    //     NSMutableDictionary *optionsDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1385295655043516",ACFacebookAppIdKey, @[@"email"], ACFacebookPermissionsKey,nil];

    

    // Specify App ID and permissions

    NSDictionary *options = @{

                              ACFacebookAppIdKey: @"appKey",

                              ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],

                              ACFacebookAudienceKey: ACFacebookAudienceFriends

                              };

    

    

    

    [account requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {

        if (granted) {

            NSLog(@"认证通过");

            

            if (!self.content.text) {

                

                    UIAlertView *a=[[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入要发分享的内容" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

                    [a show];

                

                return ;

            }

            

            

            NSArray *arrayAccounts=[account accountsWithAccountType:accountType];

            NSLog(@"arrayAccounts:%@",arrayAccounts);

            if ([arrayAccounts count]>0) {

                //                NSLog(@"认证通过");

                SLRequest *request = [SLRequest  requestForServiceType:SLServiceTypeFacebook

                                      

                                                         requestMethod:SLRequestMethodPOST

                                      

                                                                   URL:[NSURL URLWithString:@"https://graph.facebook.com/me/feed"]

                                      

                                                            parameters:@{@"status": self.content.text}];

                NSLog(@"account:%@",[[arrayAccounts objectAtIndex:0] class]);

                request.account=[arrayAccounts objectAtIndex:0] ;

                

                //                [request addMultipartData:UIImagePNGRepresentation([UIImage imageNamed:@"icon_fb.png"]) withName:@"pic" type:@"multipart/form-data" filename:@"a.png"];

                [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

                    id jsonObj = [NSJSONSerialization JSONObjectWithData:responseData

                                  

                                                                 options:NSJSONReadingAllowFragments error:&error];

                    NSLog(@"jsonObj:%@",jsonObj);

                    if (!error) {

                        

                        NSLog(@"%@",[jsonObj objectForKey:@"statuses"])  ;  //key更具api json决定

                        UIAlertView *a=[[UIAlertView alloc] initWithTitle:@"提示" message:@"分享成功" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

                        [a show];

                        

                    }

                    

                }];

                

            }else{

                

                UIAlertView *a=[[UIAlertView alloc] initWithTitle:@"提示" message:@"无效账户,请到设置界面设置账号信息" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

                [a show];

            }

 

            

        }

    }];

    

    

}

//未验证成功

猜你喜欢

转载自siruoxian.iteye.com/blog/1979586