2013-10-23 174 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

相關問題