简体   繁体   中英

is it possible to tag a post/photo using ios social framework?

In my app I need to tag my photo/posts. Is this possible using social framework or Should I use Facebook-sdk for this?. Also can I get friends list from social framework? any help to achieve this?

Tagging a photo or post can only be done using the FacebookSDK for iOS while getting your friends list is possible using both the SocialFramework and the FacebookSDK for iOS.

You can use this code to get your friends list using the SocialFramework.

- (void)getFbFriends
{
    ACAccountStore *store = [[ACAccountStore alloc] init];

    ACAccountType *facebookTypeAccount = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSDictionary *options = @{
                              ACFacebookAppIdKey: facebookAppId,
                              ACFacebookPermissionsKey: @[@"email"],
                              ACFacebookAudienceKey: ACFacebookAudienceFriends
                              };

    [store requestAccessToAccountsWithType:facebookTypeAccount
                                   options:options
                                completion:^(BOOL granted, NSError *error){
                                    if(granted)
                                    {
                                        NSArray *accounts = [store accountsWithAccountType:facebookTypeAccount];
                                        ACAccount *facebookAccount = [accounts lastObject];

                                        NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];
                                        SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                                                  requestMethod:SLRequestMethodGET
                                                                                            URL:meurl
                                                                                     parameters:nil];
                                        merequest.account = facebookAccount;

                                        NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];

                                        SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                                                requestMethod:SLRequestMethodGET
                                                                                          URL:requestURL parameters:@{@"fields":@"id,name,picture,first_name,last_name,gender"}];

                                        request.account = facebookAccount;


                                        [request performRequestWithHandler:^(NSData *data,
                                                                             NSHTTPURLResponse *response,
                                                                             NSError *error) {

                                            if(!error)
                                            {
                                                NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

                                                if([list objectForKey:@"error"]!=nil)
                                                {
                                                    // if error occured e.g. Invalid Auth etc.
                                                }
                                                else
                                                {
                                                    NSMutableArray *FBFriends = [[NSMutableArray alloc] init];
                                                    [FBFriends addObject:[userInfo objectForKey:@"id"]];
                                                    NSLog(@"friends %@", list);
                                                }
                                            }
                                            else
                                            {
                                                NSLog(@"Error");
                                            }

                                        }];
                                    }
                                    else
                                    {
                                        NSLog(@"Error grant access");
                                    }
                                }];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM