我使用Facebook 3.1并尝试对特定帖子发表评论。我使用了以下代码。我在创建会话时也使用了下面提到的权限:
read_stream,offline_access,publish_stream,share_item
代码:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"This is my comment", @"message", nil];
NSString *string=[NSString stringWithFormat:@"https://graph.facebook.com/153125724720582_184234384932460/comments?access_token=%@",appDelegate.session.accessToken];
[FBRequestConnection startWithGraphPath:string
parameters:params
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
} else {
NSLog(@"Result: %@", result);
}
}];
Response :
Result: {
comments = 1;
id = "https://graph.facebook.com/153125724720582_184234384932460/comments";
}
但是我的消息没有在评论的帖子ID上更新。
我也尝试过与Post请求相同的代码,但响应是:
Result: {
"FACEBOOK_NON_JSON_RESULT" = false;
}
您应该使用 HTTP POST 并确保用户已授予publish_stream
权限。
应将 API 调用(和访问令牌)复制并粘贴到 Graph 资源管理器中,以测试调用。
(还可以使用 access_token 调试器来确保权限存在)
你应该使用这个
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Test Comment", @"message", nil];
[FBRequestConnection startWithGraphPath:@"153125724720582_184234384932460/comments"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
NSLog(@"Error: %@", [error localizedDescription]);
else
NSLog(@"Result: %@", result);
}];