I know this seems to basic, but I’m trying to figure out a way to “Like” a page on Facebook. I.e. a company page.
I found the below code to be able to like a user on Twitter which works perfect. Any insights / resources to like a page would be appreciated.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
if ( [accountStore respondsToSelector:@selector(requestAccessToAccountsWithType: options: completion:)] )
{
[accountStore requestAccessToAccountsWithType:accountType options:nil
completion:^(BOOL granted, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if (granted)
{
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:@"@nwmobiledev" forKey:@"screen_name"];
[tempDict setValue:@"true" forKey:@"follow"];
//Code specific to iOS6 or later
[followRequest setAccount:twitterAccount];
[followRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
NSLog(@"%@", output);
if (error) {
dispatch_async(dispatch_get_main_queue(), ^{
//Update UI to show follow request failed
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook Cancelled" message:@"Failed" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
});
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
//Update UI to show success
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook Cancelled" message:@"Success" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
});
}
}];
}
}
});
}];
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
//Update UI to show follow request completely failed
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook Cancelled" message:@"Facebook Post Cancelled" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
});
}