I want to share a link on the user's wall with social.framework, if I try to do it with my account (admin of facebook app) and with device there isn't any problem, If I try to do it with simulator I get this error:
while if I try with another account I get this error:
Code:
code = 190;
message = "The access token was invalidated on the
device."; type = OAuthException;
while if I try with another account I get this error:
Code:
Error Domain=XPCObjectsErrorDomain Code=2 "The operation couldn’t be
completed. (XPCObjectsErrorDomain error 2.)"
This is the code:
Code:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{ACFacebookAppIdKey : @"xxxxx",
ACFacebookPermissionsKey : @[@"email", @"publish_stream"],
ACFacebookAudienceKey:ACFacebookAudienceFriends};
[accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];
NSDictionary *parameters = @{@"message" : @"Prova anche tu xxx!",
@"link": @"https://www.facebook.com/pages/"};
NSURL *URL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:URL
parameters:parameters];
[request setAccount:[accounts lastObject]];
[request performRequestWithHandler:^(NSData *respData, NSHTTPURLResponse *urlResp, NSError *error) {
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:respData
options:kNilOptions
error:&error];
NSLog(@"Response %@", responseDictionary.allValues);
}];
}
else {
NSLog(@"Accesso in scrittura negato %@", error);
}
}];