繁体   English   中英

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

[英]Facebook Graph API/FQL to check whether user liked a post

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

这是我所做的:(在获得read_stream许可后的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,但未成功。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM