在iOS 6中使用SLRequest与Facebook
问题描述:
我目前正试图用一个SLRequest发布一个状态上的Facebook,这是我的代码有:在iOS 6中使用SLRequest与Facebook
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSLog(@"0");
[accountStore requestAccessToAccountsWithType:accountType options:@{ACFacebookAppIdKey : @"00000000000", ACFacebookPermissionsKey : @"publish_stream", ACFacebookAudienceKey : ACFacebookAudienceFriends} completion:^(BOOL granted, NSError *error) {
if(granted) {
NSLog(@"1");
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
NSLog(@"2");
if ([accountsArray count] > 0) {
NSLog(@"3");
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
NSLog(@"4");
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:@"https://graph.facebook.com/me/feed"]
parameters:[NSDictionary dictionaryWithObject:post forKey:@"message"]];
NSLog(@"5");
[facebookRequest setAccount:facebookAccount];
NSLog(@"6");
[facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
NSLog(@"%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}];
}
}
}];
但是代码,我不希望过去if(granted){
,但我不知道为什么我所做的不工作。任何帮助,将不胜感激!
答
在我的情况下,为了解决这个问题,我在Facebook上的APP的属性中注册了Bundle ID。
在Facebook上编辑您的APP并查找“选择您的应用如何与Facebook集成”,并在“本机iOS应用”的“iOS Bundle ID”中注册项目的Bundle ID。
如果没有你的情况下,尝试读取错误消息:
if(granted) {
...
}
else {
NSLog([NSString stringWithFormat:@"%@", error.localizedDescription]);
}
答
如果error.code == 6,那么这就是如果用户未从设置签署成为Facebook的将出现的错误信息应用程序。
欢呼的人!它看起来像我没有正确地设置它的脸的一面,谢谢你的帮助。 –
错误回来,因为零和授予是(:()( –
@ Yudmt我已经设置,但仍然没有工作。关于其他选项,如“iPhone应用程序商店ID”“Facebook登录”等?都是mendetory? – Hitarth