Like Page on Facebook

24 views
Skip to first unread message

Bill Frowine, PMP

unread,
Mar 12, 2014, 2:00:41 AM3/12/14
to pdx-cocoa...@googlegroups.com
Hello All:

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.

Bill


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

                         

                         SLRequest *followRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.json"] parameters:tempDict];

                         

                         // To unfollow hit URL-https://api.twitter.com/1.1/friendships/destroy.json

                         

                         [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];

            

            

            

        });
    }

    

    


Janine Ohmer

unread,
Mar 12, 2014, 2:16:19 AM3/12/14
to pdx-cocoa...@googlegroups.com, Bill Frowine, PMP
I haven't tried to do this and it looks like Facebook frowns upon it, but I see several suggestions like this one:


Good luck!

janine

Bill Frowine, PMP

unread,
Mar 12, 2014, 2:27:42 AM3/12/14
to pdx-cocoa...@googlegroups.com
Thanks Janine!

Thanks for responding.  I found a way to do this using other methods, but I find using a webview is kinda clunky.  Really surprised FB really doesn’t like being able to “like” a page from an app.  If I find something that works I will defintely share.

Bill


--
You received this message because you are subscribed to the Google Groups "pdx-cocoaheads-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdx-cocoaheads-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages