我目前正在尝试使用 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 上的应用程序的属性中注册了 Bundle ID。
在 facebook 上编辑您的 APP,找到“选择您的应用程序与 Facebook 的集成方式”,并在“本机 iOS 应用程序”中的“iOS Bundle ID”上注册您项目的 Bundle ID。
如果不是您的情况,请尝试阅读错误消息:
if(granted) {
...
}
else {
NSLog([NSString stringWithFormat:@"%@", error.localizedDescription]);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)