Facebook的图形API不像一个喜欢交不像、图形、喜欢、Facebook

2023-09-08 00:12:18 作者:丧真的很快乐

我在我的应用程序的方法,允许用户喜欢在他/她的新闻源帖子。它做了一个简单的图表要求使用 HttpMethod.POST 。但是,当我尝试使用 HttpMethod.DELETE 做一个不像的动作,我得到一个错误回调:

  02-08 00:35:57.298:I /详细信息(2628):{响应:响应code:403,graphObject:空,错误:
{的HTTPStatus:403,错误code:200,错误类型:OAuthException,的errorMessage:(#200)
饲料的故事发布到其他用户禁用该应用},isFromCache:假}
 

现在我认为这事做的最新尝试,以使该与Facebook整合所有的应用程序使用所有Facebook的寻找对话和风格,但我可能是错的。这里的路线图后有我的怀疑:

  

删除能力,通过图形API我们将张贴到朋友的墙壁   删除通过图形来发布到用户的朋友的墙壁的能力   API。具体而言,对[USER_ID] /饲料的帖子,其中[user_ID的]是   不同于会话的用户,或stream.publish调用其中   target_id用户从会话用户的不同,将失败。如果你   要允许人们张贴到朋友的时间表,调用   饲料对话框。故事包含的朋友通过用户提到标记或   行动标签会显示好友的时间轴上(假设   朋友批准标签)。欲了解更多信息,请参阅此博客文章。

这是什么,我可以做错误的,或者是Facebook的只是毁了我的任何想法?谢谢!

编辑:这里的code我用运行要求

 请求likeRequest =新的请求(Utility.fbSession,NULL,NULL,NULL,新Request.Callback(){
    @覆盖
    公共无效onCompleted(响应响应){
        串responseString = response.toString();
        Log.i(详细信息,responseString);
        updateDetail();
    }
});
HttpMethod nextLikeCall = HttpMethod.DELETE;
likeRequest.setHttpMethod(nextLikeCall);
likeRequest.setGraphPath(的itemId +/喜欢);
likeRequest.executeAsync();
 
如何打造一款让人爱不释手的产品

解决方案

当你抢从图中数据的帖子ID,它应该像一个格式:XXXXX_YYYYY。 xxxxx的仅仅是用户ID和YYYYY是实际的文章ID。你需要做的是提取和使用后的ID图给你的只是YYYYY部分。而不是graph.facebook.com/XXXXX_YYYYY/likes左右....你要发送graph.facebook.com/YYYYY/likes。这将既喜欢和unliking工作,可以在图形浏览器测试第一黑客在一起的子字符串的提取方法之前。

不知道如何提取Android上一个字符串的一部分,但我知道在Objective-C / iOS的,这是可以做到这样的(code未经测试,仅供参考/想法):

  SString * actualPostIdStr; //该字符串,我们将会把实际postId中
的NSString * oldIdStr = //<保证字符串格式XXXXX_YYYYY>
NSInteger的charCount = [oldIdStr长度] //得到原XXXXX_YYYYY字符串的长度
NSRange fRangeCount = [oldIdStr rangeOfString:@_]; //获取的字符数删除(XXXXXX)


如果(fRangeCount.location!= NSNotFound){
    NSInteger的startingPos = fRangeCount.location + 1; //得到实际postId的起始字符位置
    actualPostIdStr = [[oldIdStr substringWithRange:NSMakeRange(startingPos,charCount  -  startingPos)复印件];
}
 

希望这有助于。

编辑: 好了,我一直在玩弄喜欢整天...看来,这种方法有时不起作用,但一切都取决于图形对象的,你尝试喜欢/不同的类型。比如...普通状态的帖子,这个方法效果很好。不过,我试图想用邮件/故事后物体的照片时,遇到了一个问题。事实证明,在图形数据为这种类型的交对象的带有照片,有一个额外的放慢参数称为的object_id,除了普通的ID,也就是在状态后的图形数据。在这种情况下,用照片和故事后,你需要通过OBJECT_ID,不变的成功unliking。

这个烂摊子似乎无论是在FB结束一个错误,或者他们正在变化,不允许从图形API和放喜欢/ unlikes;只是忘了/有没有告诉我们,但:)希望是前者。在此同时,你只是将不得不用我上面的回答,但只要确保你测试与许多不同类型的对象后,你可以找到的,而且如果条件下使用时,不同的ID(ID的一部分......OBJECT_ID...等)是必需的。

I have a method in my app that allows the user to "like" a post in his/her news feed. It's done with a simple graph request using HttpMethod.POST. But when I try to do an "unlike" action using HttpMethod.DELETE, I get an error callback:

02-08 00:35:57.298: I/Detail(2628): {Response:  responseCode: 403, graphObject: null, error: 
{HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) 
Feed story publishing to other users is disabled for this application}, isFromCache:false}

Now I assume this has something to do with the latest attempt to make all apps that integrate with Facebook use all Facebook looking dialogs and styles, but I could be wrong. Here's the roadmap post that has me suspicious:

Removing ability to post to friends walls via Graph API We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag). For more info, see this blog post.

Any ideas on what I could be doing wrong, or is Facebook just ruining me? Thanks!

EDIT: Here's the code I'm using to run the request.

Request likeRequest = new Request(Utility.fbSession, null, null, null, new Request.Callback() {
    @Override
    public void onCompleted(Response response) {
        String responseString = response.toString();
        Log.i("Detail", responseString);
        updateDetail();
    }
});
HttpMethod nextLikeCall = HttpMethod.DELETE;
likeRequest.setHttpMethod(nextLikeCall);
likeRequest.setGraphPath(itemId+"/likes");
likeRequest.executeAsync();

解决方案

When you grab the post id from the graph data, it should be in a format like: XXXXX_YYYYY. The XXXXX is simply the users id and YYYYY is the actual post id. What you need to do is extract and use just the YYYYY portion of the post id that graph gives you. so instead of graph.facebook.com/XXXXX_YYYYY/likes.... you want to send graph.facebook.com/YYYYY/likes. This will work with both liking and unliking, you can test in graph explorer first before hacking together a substring extraction method.

Not sure how to extract a section of a string on Android, but I know in Objective-C/iOS, it can be done like this (code not tested, for reference/idea) :

SString *actualPostIdStr;      //The String we will put the actual postId in
NSString *oldIdStr          =   //<the string in format XXXXX_YYYYY>
NSInteger charCount         =   [oldIdStr length]; //get the length of the original XXXXX_YYYYY string
NSRange fRangeCount         =   [oldIdStr rangeOfString:@"_"]; //get count of characters to remove (XXXXXX)


if (fRangeCount.location != NSNotFound){
    NSInteger startingPos   =   fRangeCount.location + 1; //get the starting character position of the actual postId
    actualPostIdStr         =   [[oldIdStr substringWithRange:NSMakeRange(startingPos, charCount - startingPos)] copy];
}

Hope this helps.

EDIT: Ok, so I have been playing around with likes all day... It seems that this method sometimes doesn't work, but it all depends on the type of graph object which you are attempting to like/unlike. For example... plain status posts, this method works perfectly. However, I ran into a problem when trying to like a photo with a message/story post object. It turns out, in the graph data for this type of post object with photo, there is an additional paramter called "object_id", in addition to the plain "id" that is in status post graph data. in this case, with the photo and story post, you need to pass the "object_id", unaltered for successful unliking.

This mess seems like either a bug on FB's end, or they are making changes and disallowing likes/unlikes from graph api & just forgot/haven't to told us yet :) hopefully the former. In the mean time, you're just going to have to use my above answer, but just make sure you test with as many different types of post objects you can find, and use if conditions when a different id (portion of "id"... "object_id"... etc) is required.