简体   繁体   中英

How to post checkin on Facebook?

I need to checkin on Facebook, without using the default checkin option that comes with Facebook iOS SDK, because I need to filter the Facebook places, so that user can only checkin using places I filtered. I have tried this using Facebook graph api.

NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:accsstoken,@"access_token",@"253651184683030",@"place",@"I m here in this place",@"message",@"30.893075018178,75.821777459326",@"coordinates", nil];

[FBRequestConnection startWithGraphPath:@"/me/checkins"
                             parameters:dict
                             HTTPMethod:@"POST"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          id result,
                                          NSError *error
                                          ) {
                          NSLog(@"Error...%@",error);

                         }]; 

if anybody know about this, Do let me know ? Any kind of help will be appreciated.

So first off, according to the Facebook API docs, the action you are trying to perform is deprecated.

You can read about it here .

Now, you use /{user-id}/feed, and just add a location ID. Read the docs for this action here .

As for filtering, Not sure how that is a problem. Just filter the list of locations you show the user however you want and make sure to only pass one of those locations as the place .

Here is a working code:

_place.facebookId = place id of location to checkin in

listFriends = a list of friend's id to checkin with

-(void)publishToFacebook:(NSString *)message
{
// Create the parameters dictionary that will keep the data that will be posted.
NSMutableArray *fArray = [NSMutableArray new];
for (RCPerson *person in listFriends)
{
    [fArray addObject:person.ID];
}

NSMutableDictionary * params = [NSMutableDictionary new];

if(fArray.count > 0)
{
    params = [NSMutableDictionary dictionaryWithObjectsAndKeys: message, @"message",[fArray componentsJoinedByString:@","], @"tags",  _place.facebookId, @"place", nil];

}
else
{
    params = [NSMutableDictionary dictionaryWithObjectsAndKeys: message, @"message", _place.facebookId, @"place", nil];

}

NSLog(@"params %@", params);
FBRequest *postRequest = [FBRequest requestWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];
postRequest.session = FBSession.activeSession;
if(![postRequest.session.permissions containsObject:@"publish_stream"])
{

    [postRequest.session requestNewPublishPermissions:@[@"publish_stream", @"publish_actions"] defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error) {
        [postRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            NSLog(@"error %@", error.description);
            if(error)
            {
                dispatch_async(dispatch_get_main_queue(), ^(void) {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook error" message:[self parseError:error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alert show];
                });
            }
            NSLog(@"%@", result);

            //[self checkinMe];

        }];
    }];
}
else
{
    [postRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        NSLog(@"error %@", error.description);
        if(error)
        {

            dispatch_async(dispatch_get_main_queue(), ^(void) {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook error" message:[self parseError:error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
            });
        }
        NSLog(@"%@", result);
        //[self checkinMe];

    }];
}

}

Publishing with /checkin is now deprecated. Check out the documentation - /checkin

You have to use Open Graph Actions to do the same, here is the discussion on same: facebbok sdk Integrate interactive map in a post like Foursquare

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