0

我正在尝试在我的 iOS 应用程序中使用以下 FQL 语句

SELECT comment_info,likes,share_count FROM stream WHERE post_id

出于某种原因,我不断从图形 API 中收到错误消息

解析错误:意外的“?” 在位置 70 OAuth 异常

由于某种原因,该位置移动了一个“?” 被添加到我的 SLRequests 的末尾?这是我正在使用的代码块。现在让我发疯,因为我已经尝试了很多事情,但仍然无法摆脱这个,但在使用相同的方法拉 /me/home 时工作正常。

        NSLog(@"ID: %@", graphID);

        NSString* urlText = [NSString stringWithFormat: @"https://graph.facebook.com/fql?q=SELECT comment_info,likes,share_count FROM stream WHERE post_id = '%@'", graphID];
        urlText = [urlText stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL *url = [NSURL URLWithString: urlText];

        SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:url parameters: nil];
        request.account = self.facebookAccount;

        [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
            NSLog(@"url %@", request.URL.absoluteURL);
            NSString * responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
            NSError* responseError;

            NSDictionary* jsonDict = [NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&responseError];
            NSArray * dataArray = jsonDict[@"data"];

            [dataArray enumerateObjectsUsingBlock:^(NSDictionary * infoDictionary, NSUInteger idx, BOOL *stop) {
                NSNumber *likesCount;
                NSNumber *commentsCount;

                likesCount = [NSNumber numberWithInt: [infoDictionary[@"likes"][@"count"] integerValue]];
                commentsCount = [NSNumber numberWithInt: [infoDictionary[@"comment_info"][@"comment_count"] integerValue]];

                NSLog(@"likes %@", likesCount);
            }];
        }];
4

3 回答 3

1

这是正确的方法

NSString* urlString = @"https://graph.facebook.com/fql";
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString* query = [NSString stringWithFormat:@"SELECT user_id FROM like WHERE post_id='%@' AND user_id=me()", postId];
SLRequest* request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                        requestMethod:SLRequestMethodGET
                                                  URL:[NSURL URLWithString:urlString]
                                           parameters:@{@"q" : query}];

request.account = <account>;
于 2014-01-08T05:29:10.967 回答
0

我建议你像这样使用带有 'q' 参数的 NSDictionary

NSDictionary *params = @{ @"q" : [NSString stringWithFormat: @"https://graph.facebook.com/fql?q=SELECT comment_info,likes,share_count FROM stream WHERE post_id = '%@'", graphID] };

并将其作为参数发送到您的 SLRequest。

于 2013-06-07T20:06:59.053 回答
0

试试这个

NSString* urlString = @" https://graph.facebook.com/fql ";

urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSString* query = [NSString stringWithFormat:@"SELECT comment_info,likes,share_count FROM stream WHERE post_id = '%@'", graphID];

SLRequest* request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:urlString] 参数:@{@"q" : query}];

request.account=self.facebookAccount;
[request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error)

 {
     if(!error)
     {

         NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
        NSLog(@data from facebook : %@“,list);
     }
     else
     {

         NSLog(@"error while fetching data from facebook : %@",error);
     }


 }];
于 2014-04-02T12:42:02.933 回答