问题 使用新的sdk在我的Facebook墙上发布


我正在使用新的Facebook SDK通过以下方式在我的墙上发布 他们的指示

我从应用程序获得授权,但当我尝试发布时,我收到错误 Error: HTTP status code: 400 下面我发布我的代码

 - (void)viewDidLoad
{
self.postParams =
 [[NSMutableDictionary alloc] initWithObjectsAndKeys:
 @"https://developers.facebook.com/ios", @"link",
 @"https://developers.facebook.com/attachment/iossdk_logo.png", @"picture",
 @"Facebook SDK for iOS", @"name",
 @"build apps.", @"caption",
 @"testing for my app.", @"description",
 nil]; 

[self.postParams setObject:@"hgshsghhgsls" forKey:@"message"];

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

-(IBAction)Post{
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openSessionWithAllowLoginUI:YES];


[FBRequestConnection   startWithGraphPath:@"me/Mac" parameters:self.postParams HTTPMethod:@"POST"
                        completionHandler:^(FBRequestConnection *connection,id result,NSError *error) {
                            NSString *alertText;
                             if (error) {
                             alertText = [NSString stringWithFormat:@"error: domain = %@, code = %d, des = %d",error.domain, error.code,error.description];
                             } 
                             else 
                             {
                             alertText = [NSString stringWithFormat:@"Posted action, id: %@",[result objectForKey:@"id"]];
                             }
                             // Show the result in an alert
                             [[[UIAlertView alloc] initWithTitle:@"Result" message:alertText delegate:self cancelButtonTitle:@"OK!"
                             otherButtonTitles:nil]show];
                        }]; 




}

我在这里做错了什么,任何建议都会很棒,这个新的SDK是测试版?还是一个完整的?


3563
2017-08-30 09:35


起源

你可以发布整个错误行吗?做一个NSLog(@“%@”,错误);然后你看到整个描述,为什么它会抛出400错误。或者发布警报输出的消息...... - Fab1n
2012-08-30 14:33:05.225 NewFbLogin [1275:fe03]错误:HTTP状态码:400 - Ghouse
抱歉这个愚蠢的问题,但你有一个有效的登录和Facebook会话?也许按照这个tut: developers.facebook.com/docs/tutorials/ios-sdk-tutorial/... - Fab1n
这是nslog,错误很大,我无法完全发布.Error Domain = com.facebook.sdk Code = 5“操作无法完成。(com.facebook.sdk错误5.)”UserInfo = 0x6b8ab10 {com .facebook.sdk:ParsedJSONResponseKey = <CFBasicHash 0x68cc3a0 [0x1502b48]> {type = mutable dict,count = 2, - Ghouse
另一个问题:什么是我/ Mac?它必须是我/饲料,如果你想发布...... - Fab1n


答案:


如果您遇到任何问题,请尝试在您有兴趣调试的请求调用之前添加此代码来启用日志记录:

[FBSettings setLoggingBehavior:[NSSet setWithObjects:FBLoggingBehaviorFBRequests, FBLoggingBehaviorFBURLConnections, nil]];


12
2017-09-19 09:44



很棒的提示。感谢分享。 - JaredH


最后我解决了问题,我必须在我的应用权限页面中将Auth Token参数更改为URLFragment然后它正在工作


4
2017-08-30 11:59



我可以在这里知道投票的原因 - Ghouse
您好AnswerMe,您能解释一下解决方案的内容吗?当您说出您的应用权限页面时,您的意思是在developer.facebook.com上吗?也许你一步一步做了什么?谢谢。 - sixstatesaway
是的在developer.facebook.com我选择了我的应用程序,然后编辑设置,在下一页我选择了权限,在左侧,并在该Auth令牌参数选项我更改为URL片段选项.thats我所做的一切,它是加工 - Ghouse
感谢你的回答。我有同样的错误,并用正确的答案解决了它 这个问题 但也许这会对某人有所帮助。我不知道为什么有人下来投票给你。 - sixstatesaway
我改变了这个参数,但仍然没有运气:( - Shmidt


我将这个框架用于我的项目。它工作正常。这是我的相关代码

   -(IBAction)logIn:(id)sender;
{
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (!FBSession.activeSession.isOpen) {
    [appdelegate sessionOpener];
}
else {
    [self loginHelp];
}

而我的sessionOpener函数是;

 -(void) sessionOpener

{

[FBSession sessionOpenWithPermissions:nil
                    completionHandler:^(FBSession *session,
                                        FBSessionState status,
                                        NSError *error) {
                        // session might now be open.
                        if (!error) {
                            [self.viewController loginHelp];
                        }
                    }];

 NSLog(@"%d", FBSession.activeSession.isOpen);
NSLog(@"%@", FBSession.activeSession.description );

}

这个对我有用。可能对你有所帮助。


0
2017-12-29 10:42





检查会话发布权限。

它对我很好。

[FBSession openActiveSessionWithPublishPermissions:[[NSArray alloc] initWithObjects:@"publish_stream",@"email", nil]
                                   defaultAudience:FBSessionDefaultAudienceFriends
                                      allowLoginUI:YES
                                 completionHandler:^(FBSession *session,
                                                     FBSessionState state, NSError *error) {
                                     [self sessionStateChanged:session state:state error:error];
                                 }];

0
2018-04-12 23:24