iOS中的事件的FQL查询不起作用

时间:2013-04-03 21:51:26

标签: ios events facebook-fql

所以,这是我的FQL查询,用于检索用户事件的场地:

    NSString* fql1 = [NSString stringWithFormat:
                      @"SELECT venue from event WHERE eid in (SELECT eid FROM event_member WHERE uid = me())"];
    NSString* fql2 = [NSString stringWithFormat:
                      @"SELECT name FROM page WHERE page_id IN (SELECT venue.id FROM #event_info)"];
    NSString* fqlStr = [NSString stringWithFormat:
                     @"{\"event_info\":\"%@\",\"event_venue\":\"%@\"}",fql1,fql2];
    NSDictionary* params = [NSDictionary dictionaryWithObject:fqlStr forKey:@"queries"];

    FBRequest *fql = [FBRequest requestWithGraphPath:@"fql.query" parameters:params HTTPMethod:@"POST"];

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

查询本身很好,我在Graph API Explorer中尝试过。但是我收到了这个错误:

error:Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1f01da20 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 240;
            message = "(#240) Requires a valid user to be specified (either via the session or via the API parameter for specifying the user.";
            type = OAuthException;
        };
    };
    code = 403;
}, com.facebook.sdk:ErrorSessionKey=<PFReceptionist: 0xb2426b0>}

我做错了什么?这不是我对会话的第一个查询,我已经要求user_events权限和简单的非FQL查询,以便正常工作。

1 个答案:

答案 0 :(得分:1)

这是它应该是什么样子。如果有错误,请纠正我。

NSString *query =
@"{"
@"'event_info':'SELECT eid, venue, name, start_time, end_time, creator, host, attending_count from event WHERE eid in (SELECT eid FROM event_member WHERE uid = me())',"
@"'event_venue':'SELECT name, location, page_id FROM page WHERE page_id IN (SELECT venue.id FROM #event_info)',"
@"}";
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:
                            query, @"q", nil];

[FBRequestConnection startWithGraphPath:@"/fql" parameters:queryParam
                    HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection,
                    id result, NSError *error) {
    if (error) {
        NSLog(@"Error: %@", [error localizedDescription]);
    } else {

        NSArray* data = [result objectForKey:@"data"];
        NSArray* events = [((NSDictionary*) data[0]) objectForKey:@"fql_result_set"];
        NSArray* venues = [((NSDictionary*) data[1]) objectForKey:@"fql_result_set"];

        NSLog(@"Result: %@", result);
    }        
}