OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 Facebook 上发布签到? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:14
标题: ios - 如何在 Facebook 上发布签到?

我需要在 Facebook 上签到,而不使用 Facebook iOS SDK 附带的默认签到选项,因为我需要过滤 Facebook 地点,以便用户只能使用我过滤的地点签到。 我已经使用 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"OST"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          id result,
                                          NSError *error
                                          ) {
                          NSLog(@"Error...%@",error);

                         }]; 

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



Best Answer-推荐答案


这是一个工作代码:

_place.facebookId = 签到地点的地点 ID

listFriends = 用于签到的好友 ID 列表

-(void)publishToFacebookNSString *)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"OST"];
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];

    }];
}

}

关于ios - 如何在 Facebook 上发布签到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22904285/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4