Facebook SDK API IOS发布到用户墙时出错

时间:2012-08-30 03:17:46

标签: objective-c ios facebook api sdk

我在尝试发布到用户的Facebook墙时遇到以下错误,我似乎无法找到源代码。任何人都对这个问题有所了解吗?

2012-08-29 22:14:38.490 CanP[405:707] Error: HTTP status code: 400
2012-08-29 22:14:38.494 CanP[405:707] FBSDKLog: Response <#1111> <Error>:
The operation couldn’t be completed. (com.facebook.sdk error 5.)

应该将消息发布到Facebook墙的运行方法如下:

[FBSettings setLoggingBehavior:[NSSet setWithObjects:
                                FBLoggingBehaviorFBRequests,
                                nil]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"My test app", @"name",
                               @"http://www.google.com", @"link",
                               @"FBTestApp app for iPhone!", @"caption",
                               @"This is a description of my app", @"description",
                               @"Hello!\n\nThis is a test message\nfrom my test iPhone app!", @"message",
                               nil];

// Publish.
// This is the most important method that you call. It does the actual job, the message posting.
[facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

2 个答案:

答案 0 :(得分:2)

正如C Abernathy所建议的那样,你应该“在错误行放置一个断点并查看错误变量,然后深入查看一个名为userInfo的字典,该字典应包含更易读的错误消息。”

对于我们这些测试新Facebook集成的人来说,最常见的问题可能会显示在error.userInfo "com.facebook.sdk.ParsedJSONResponseKey"中:

message = "(#506) Duplicate status message";

改变您用来测试Facebook集成的文本,您可能会发现您的代码运行正常!

答案 1 :(得分:1)

我建议您使用新的SDK 3.1方法进行发布。

[FBRequestConnection
 startWithGraphPath:@"me/feed"
 parameters:params
 HTTPMethod:@"POST"
 completionHandler:^(FBRequestConnection *connection,
                     id result,
                     NSError *error) {
     if (error) {
         /* Handle error */
     } else {
         /* Handle success */
     }
 }];

有关分步教程,请参阅:https://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/

还要确保首先要求发布publish_action权限,以确保可以发布到墙上。

如果仍然遇到问题,请在错误行中放置一个断点并查看错误变量,然后深入查看名为userInfo的字典,该字典应包含更易读的错误消息。