如何在Facebook上发布入住?

时间:2014-04-07 05:32:49

标签: ios objective-c facebook facebook-graph-api facebook-checkins

我需要在Facebook上签到,而不使用Facebook iOS SDK附带的默认签入选项,因为我需要过滤Facebook位置,以便用户只能使用我过滤的地方签到。 我使用Facebook图表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);

                         }]; 

如果有人知道这件事,请告诉我吗? 任何形式的帮助将不胜感激。

3 个答案:

答案 0 :(得分:1)

首先,根据Facebook API文档,您尝试执行的操作已弃用。

您可以阅读here

现在,您使用/ {user-id} / feed,只需添加位置ID即可。阅读此操作的文档here

至于过滤,不确定这是怎么回事。只需根据需要过滤显示用户的位置列表,并确保仅将其中一个位置作为place传递。

答案 1 :(得分:1)

这是一个有效的代码:

_place.facebookId =要签入的位置ID

listFriends =要使用

签入的朋友ID列表
-(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];

    }];
}

}

答案 2 :(得分:0)

现在不推荐使用/checkin发布。查看文档 - /checkin

你必须使用Open Graph Actions来做同样的事情,以下是对它的讨论:facebbok sdk Integrate interactive map in a post like Foursquare