我想在Facebook上评论一篇帖子,我和帖子一样使用。对于像帖子一样,它有效,但是就像评论一样失败。
文档: https://developers.facebook.com/docs/graph-api/reference/object/likes
我的代码:
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"/%@/likes", postId_]
parameters:nil
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{ //Error:
}];
错误:
错误Domain = com.facebook.sdk Code = 5“操作无法完成。(com.facebook.sdk错误5)”UserInfo = 0x158999b0 {com.facebook.sdk:HTTPStatusCode = 400,com。 facebook.sdk:ParsedJSONResponseKey = { body = { error = { 代码= 100; message =“(#100)找到所请求的故事时出错”; type = OAuthException; }; }; 代码= 400; },com.facebook.sdk:ErrorSessionKey =}
答案 0 :(得分:1)
我是这样做的,它就像一个魅力
// post is my module object, encapsulates the info form the post
// pass the post ID
NSString *graphPath = [NSString stringWithFormat:@"%@/likes", post.postID];
FBRequest *request = [FBRequest requestForGraphPath:graphPath];
// DELETE or POST the like
NSString *method = post.liked?@"DELETE":@"POST";
[request setHTTPMethod:method];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
BOOL success = YES;
success = (error)?NO:YES;
if(success) {
}
}];
注意:确保您具有发布权限
答案 1 :(得分:0)
在我的项目中,我使用以下代码:
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:URL, @"object", nil];
if (FBSession.activeSession.isOpen) {
if (FBSession.activeSession.accessTokenData.accessToken) {
[FBRequestConnection startWithGraphPath:@"/me/og.likes"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(@"Just liked on Facebook!");
}];
} else NSLog(@"Cannot open FBSession");
}
没有打开或初始化FBSession的代码 - 我希望,这不是问题吗?
答案 2 :(得分:0)
我想,我们都可以信任Facebook,是吗? :)
转到https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes,选择" IOS SDK"选项卡并查看代码。