我目前正在尝试使用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){,但我不知道为什么我所做的事情不起作用。任何帮助都将不胜感激!
发布于 2012-09-25 02:45:13
在我的例子中,为了解决这个问题,我在facebook上的应用程序的属性中注册了Bundle ID。
在facebook上编辑你的应用程序,查找“选择你的应用程序如何与Facebook集成”,并在“本地iOS应用程序”中的"iOS捆绑包ID“上注册你的项目的捆绑包ID。
如果不是您的情况,请尝试阅读错误消息:
if(granted) {
...
}
else {
NSLog([NSString stringWithFormat:@"%@", error.localizedDescription]);
}发布于 2015-09-02 20:11:45
如果是error.code == 6,则这是如果用户没有从设置应用程序登录到Facebook时会出现的错误消息。
https://stackoverflow.com/questions/12569124
复制相似问题