在FB上创建一个活动并通过ios7邀请朋友

时间:2014-01-06 07:04:13

标签: ios invite facebook-events

您好我已经通过我的iOS应用程序通过以下代码在Facebook上创建了一个活动

-(void) createEvent:(NSString*)eventName Eventdesc:(NSString*)eventdesc EventDate: (NSString*)eventDate{
    NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me/events"];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   eventName, @"name",
                                   eventdesc, @"description",
                                   [NSString stringWithFormat:@"%@",[NSDate date]], @"start_time",
                                   nil];
    SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                              requestMethod:SLRequestMethodPOST
                                                        URL:meurl
                                                 parameters:params];

    merequest.account = _facebookAccount;

    [merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        NSLog(@"event %@", meDataString);
        if (!error) {
            UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"" message:@"Thanks for your support. Event has been created on your facebook page." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
            [alertView show];
        }else{
            UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"" message:@"Unable to create event on facebook."  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
            [alertView show];
        }

    }];
}

现在我想邀请朋友参加这个创建的活动。我搜索很多,但我没有得到任何有用的信息。 请帮忙。提前谢谢。

2 个答案:

答案 0 :(得分:0)

您可以通过发出HTTP POST to /EVENT_ID/invited/USER_ID邀请用户参加活动。您可以通过发出H TTP POST to /EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3来邀请多个用户。这两个都需要create_event权限,如果邀请成功,则返回true。

答案 1 :(得分:0)

使用以下代码解决问题

pragma mark-邀请朋友方法

- (void)inviteFriendsToEvent:(NSString *)eventID UserID:(NSMutableArray *)userID {

NSLog(@"ID=%@",[_IDArray lastObject]);
NSLog(@"Event ID:%@",_eventID);


NSData *data = [_eventID dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSLog(@"Event ID:%@",[json objectForKey:@"id"]);

NSURL *meurl = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/invited/%@",[json objectForKey:@"id"],[_IDArray lastObject]]];
//@"https://graph.facebook.com/EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3"
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                          requestMethod:SLRequestMethodPOST
                                                    URL:meurl
                                             parameters:nil];

merequest.account = _facebookAccount;

[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"Data=%@",meDataString);
}];

}