I have created a Facebook app for my iOS application in Facebook developer console, but when I use that app id, even though I get the response as success it won't get posted. Please find below my code.(even I get the id for that particular post)
But the point is when I execute same code with my existing Facebook app id(Which is currently using for my live app), this get posted and works fine, so my assumption is, there is something I have to do in Facebook app configuration in the developer console, but I couldn't find. can anyone give me a clue?
Thanks in advance.
Note : I use iOS 6 social framwork
Get User method
- (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];
}];
}
}];
}
Share method
-(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);
}
}];
}
Edit : Is it required to request special permission to use graph API when calling requestAccessToAccountsWithType
?
Finally i got it working, and my assumption was correct :) I have to add new permission when i requesting the access. So as i said it worked in my previous Facebook app ID, thats because i have already granted the permission for that app. Anyway, for those who interest to see what is the solution, find it below,
//Specify App ID and permissions
NSDictionary *options = @{
ACFacebookAppIdKey: @"xxxxxxxxxxxxxxx",
ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
Requested two new permissions publish_stream
and publish_actions