2013-10-23 114 views
0

我正在使用FQL来确定用户是否喜欢发布。当用户不喜欢任何帖子时,回复是足够好的,但是当帖子被喜欢时它仍然是一样的,我没有得到用户的(我的)user_id作为回应。Facebook Graph API/FQL来检查用户是否喜欢发布

这里就是我所做的:(授予块内得到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 =  (
    ); 
} 

输出(如果POST喜欢):

{ 
    data =  (
    ); 
} 

我试着通过帖子的id和在查询中使用post_idobject_id,但没有成功。

回答

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

相关问题