簡體   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