Facebook Graph API / FQL检查用户是否喜欢帖子

时间:2013-10-23 11:13:20

标签: ios facebook facebook-graph-api ios6 facebook-fql

我正在使用FQL来确定用户是否喜欢帖子。当用户不喜欢任何帖子时,响应已经足够好但在帖子被喜欢时保持不变,我没有得到用户的(我的)user_id作为回应。

以下是我的所作所为:(获得read_stream权限后在授予的区块内)

NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/fql"];
    NSMutableDictionary * params = [NSMutableDictionary
                                    dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"select user_id from like where object_id=%@ AND user_id=me()",postID], @"q", nil];
    SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                            requestMethod:SLRequestMethodGET
                                                      URL:requestURL
                                               parameters:params];
    request.account = [[self.accountStore accountsWithAccountType:accountTypeFacebook] objectAtIndex:0];
    [request performRequestWithHandler:^(NSData *data,
                                         NSHTTPURLResponse *response,
                                         NSError *error) {

        if(!error){
            NSDictionary *resultDictionary = [[NSDictionary alloc] init];
            resultDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
            NSLog(@"dictionary with user id's: %@",resultDictionary);
        }else{
          //handle error gracefully
        }
     }];

输出(不喜欢发布时):

{
    data =     (
    );
}

输出(喜欢发布时):

{
    data =     (
    );
}

我尝试使用post_id代替object_id传递帖子的ID和查询,但没有成功。

1 个答案:

答案 0 :(得分:1)

要检查用户是否喜欢帖子,我们需要获取数据表单流表而不是表格,请按照以下要求

Request : 
NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/fql"];
                                                       NSMutableDictionary * params1 = [NSMutableDictionary
                                                                                        dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"SELECT likes FROM stream WHERE post_id = '%@'",postID], @"q",facebookOfflineAccessToken,@"accessToken",nil];

回复:您会收到"user_likes" = 0表示不喜欢,"user_likes" = 1表示喜欢