我在 Facebook 开发人员控制台中为我的 iOS 应用程序创建了一个 Facebook 应用程序,但是当我使用该应用程序 ID 时,即使我得到成功的响应,它也不会被发布。请在下面找到我的代码。(即使我得到了那个特定帖子的 ID)
但关键是当我使用现有的 Facebook 应用程序 ID(当前用于我的实时应用程序)执行相同的代码时,这会被发布并且工作正常,所以我的假设是,我必须在 Facebook 应用程序配置中做一些事情开发者控制台,但我找不到。谁能给我一个线索?
提前致谢。
注意:我使用 iOS 6 社交框架
获取用户方法
- (void)getUserAndShare {
NSLog(@"Getting User");
if(!_accountStore)
_accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:@{ACFacebookAppIdKey: @"xxxxxxxxxxxxxx", ACFacebookPermissionsKey: @[@"email"]}
completion:^(BOOL granted, NSError *error) {
if(granted){
NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
_facebookAccount = [accounts lastObject];
NSLog(@"Success account");
[_accountStore renewCredentialsForAccount:_facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
if (error){
}
[self postPhoto:nil];
}];
}
}];
}
分享方式
-(IBAction)postPhoto{
if(!_accountStore)
_accountStore = [[ACAccountStore alloc] init];
NSDictionary *parameters = @{@"message": @"this is a resource picture 2", ACFacebookAppIdKey: @"xxxxxxxxxxxxxx"};
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:@"https://graph.facebook.com/me/photos"]
parameters:parameters];
NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"sec.jpg"]);
[facebookRequest addMultipartData: data
withName:@"source"
type:@"multipart/form-data"
filename:@"msg.jpg"];
facebookRequest.account = _facebookAccount;
[facebookRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (error) {
}
else
{
NSLog(@"Post successful");
NSString *dataString = [[NSString alloc] initWithData:responseData encoding:NSStringEncodingConversionAllowLossy];
NSLog(@"Response Data: %@", dataString);
}
}];
}
编辑:调用时是否需要请求特殊权限才能使用图形 API requestAccessToAccountsWithType
?