Like on the Facebook page, the button action

I try to implement the page as functionality from the application, I added the latest Facebook SDK and implemented all the delegates and handlers to check the session and the login status of the user in the application. His work works fine here (this has already been done in the sample code). Anyway, I found the following code on the Facebook developer site to like the page, but it doesn't seem to work.

 - (void) likeFacebookIndia { NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject]; action[@"object"] = @"http://www.facebook.com/FacebookIndia"; //action[@"object"] = @"FacebookIndia"; [FBRequestConnection startForPostWithGraphPath:@"me/og.likes" graphObject:action completionHandler:^ (FBRequestConnection *connection, id result, NSError *error) { // handle the result if(error) { NSLog(@"%@",error.localizedDescription); } else { NSLog(@"%@",result); } }]; } 

After a successful login, I used the call function above, and it ends with the next error in the likeFacebookIndia block,

The operation could not be completed. (com.facebook.sdk 5 error.)

Here are my questions:

  • I'm not sure if this is right for the page?

  • If this is correct, then what am I really missing out on?

  • Is there another way?

I have already visited the pages for FacebookLikeView and FBLikeButton and many of the issues that have already been discussed here, but none of them work with the latest update of the Facebook SDK . I liked the FacebookLikeView , but there were a lot of problems with it,

  • A UIKeyBoard displayed after the page.
  • A good time to load your Facebook page if you need to sign in, and
  • After the second one, similar to the same page as anywhere!

Update I tested the same thing in the Graph API Explorer, and it has the following result:

Graph API Explorer

{ "error": { "message": "(#100) Like actions are not yet supported against objects of this type.", "type": "OAuthException", "code": 100 } }

Update 2

I hacked into FacebookLikeView classes and solved the problems I wrote above, although it should work now? No, it does not work, because it uses FBConnect , which is now deprecated, and also, I have the latest Facebook SDK for other things that work beautifully! It would be nice if someone did a new project with the latest SDK for FacebookLikeView. [I'm already working!]

This is how I do it

 //Calling this function in `viewDidLoad` - (void) addLikeView { facebookLikeView.delegate = self; facebookLikeView.href = [NSURL URLWithString:@"http://www.facebook.com/FacebookIndia"]; facebookLikeView.layout = @"button_count"; facebookLikeView.showFaces = NO; facebookLikeView.alpha = 0; [facebookLikeView load]; } #pragma mark - Facebook Delegate -(void)sessionDoneForPageShare:(FBSession *)session state:(FBSessionState)state error:(NSError *)error { if(error) { NSLog(@"error : %@",error); } else { [facebookLikeView load]; //In logged in or logged out, we've to call this } } - (void)facebookViewControllerCancelWasPressed:(id)sender { NSLog(@"Login was cancelled by user"); } - (void)facebookViewControllerDoneWasPressed:(id)sender { NSLog(@"User tapped done button on login view"); } - (void) checkFBloggedInStatus { if (!FBSession.activeSession.isOpen) { NSArray *permissions = [NSArray array]; [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceOnlyMe allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error){ [self sessionDoneForPageShare:session state:status error:error];} ]; } } #pragma mark FacebookLikeViewDelegate methods - (void)facebookLikeViewRequiresLogin:(FacebookLikeView *)aFacebookLikeView { [self checkFBloggedInStatus]; } - (void)facebookLikeViewDidRender:(FacebookLikeView *)aFacebookLikeView { [UIView beginAnimations:@"" context:nil]; [UIView setAnimationDelay:0.5]; facebookLikeView.alpha = 1; [UIView commitAnimations]; } - (void)facebookLikeViewDidLike:(FacebookLikeView *)aFacebookLikeView { NSLog(@"liked"); } - (void)facebookLikeViewDidUnlike:(FacebookLikeView *)aFacebookLikeView { NSLog(@"unliked"); } - (void)facebookLikeView:(FacebookLikeView *)aFacebookLikeView didFailLoadWithError:(NSError *)error { NSLog(@"FacebookLikeView error: %@",error); } 

With this, I can see a similar button that can enter the browser, but then nothing will happen! It will just show the β€œLike” button every time!

This worked well with the old FBConnect SDK, the problem is with the latest Facebook SDK , you can find FacebookLikeView here ,

What am I missing?

+4
source share
2 answers

Great update!

If you see this, it means that now you do not need to fix (or hack) anything in order to support (for example, a Facebook page or any Open Graph object) in your application. With the latest release for Facebook iOS SDK (FacebookSDK.framework) they support as a button, however (while I am writing this update) in beta , but we have what we need for a long time, thanks Facebook.

Here's a direct link to the change log and a similar button and documentation yes.

Solution: [RECOMMENDED]

The Like button can be used as a Facebook page or any Open Graph object and can link to a URL or ID. Here is what the code looks like:

 FBLikeControl *like = [[FBLikeControl alloc] init]; like.objectID = @"http://shareitexampleapp.parseapp.com/photo1/"; [self addSubview:like]; 

enter image description here

(Source: Documentation ).


Old school way [NOT RECOMMENDED]

Finally, I can solve my problem, I put the solution steps, so it really helps someone who is looking for this material,

Some things you might need (from my question)

  • I use the FBConnect and Facebook SDK at the same time in my application.
  • Both work fine, FBConnect is only for FacebookLikeView - you need to replace the FBRequest class with a different name with FBConnect so that it does not contradict the latest SDK.
  • Still needed for an easy and quick solution, as this is not an ideal solution.

So let's go

How do I know if a user liked this page or not?

You need to use the Graph API and check if the user likes. Here is an example.

 https://graph.facebook.com/{USER_ID}/likes/{PAGE_ID} 

If the user liked the page in question, it will return JSON like this if the user likes the page.

 { "data": [ { "name": "SomeCafe", "category": "Restaurant/cafe", "id": "someIdWillCome", "created_time": "2013-05-07T12:32:00+0000" } ], "paging": { "next": "https://graph.facebook.com/me/likes/someIdWillCome?format=json&limit=5000&offset=5000&__after_id=someIdWillCome" } } 

And so, if the user does not like the page:

 { "data": [ ] } 

Here's the user documentation like it: https://developers.facebook.com/docs/reference/api/user/#likes

Implementation

1) Add FacebookLikeView as indicated in its docs.

2) I need to implement one HTTP request to call the above URL in order to check the current status of this page, since I could not get it from FacebookLikeView . Remember that you need to execute a GET request along with access_token.

3) Check the answer (next to the example above) and do whatever you need!

What is it!

Here are the solutions for FacebookLikeView problems that I encountered


1) FacebookLikeView gone somewhere?

This is because a popover comment hides it! below is the solution

In the FacebookLikeView.m class FacebookLikeView.m find - (void)didObserveFacebookEvent:(NSString *)fbEvent And add these lines to the end,

 if([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0f) { //NS_AVAILABLE_IOS(5_0); [[_webView scrollView] setContentOffset: CGPointMake (0, 0)]; } 

2) FacebookLikeView shows UIKeyboard !!

This is due to the focus of the comment text box after the page, below is the solution for this.

 - (void) keyboardWasShown:(NSNotification *)notification { //force hide UIKeyBoard [self.view endEditing:YES]; } 

Added notification in viewDidLoad to the class where you execute

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil]; 

This will undo the entire keyboard visible from this particular view, in my case I would not become a UITextField where I need a Facebook Like button, so if your case matters, make sure.

3) The problem of slow loading depends on many functions of the Facebook server, Internet connection or something else, so I added a download indicator to it. It takes some time, but I work as I want!


This will allow me, like / unlike the Facebook page, also to find out the current status of this particular user so that I can decide what to do!

Finally, thanks to everyone who checked this problem and will answer me! Appreciated! :)

+4
source

Sorry to tell you bad news, but you cannot like the page as a user. You may like posts, comments, and photos on behalf of the user, but not the page (the same opinion you spoke of does the same thing). If you try to do the latter, you will receive an error message

"message": "(# 3) The application is unable to make this API call."

But the good news is that you can do this using an iFrame that will load into the UIWebView. So far, this is the only solution for integrating PAGE as a button in your own application. For further reading, you can view this resource: http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-photos-and-add-a-like-button-from -your-iphone-app There you can find a section

Adding a Like Button to Your Facebook Fan Page

Hope this helps you.

+1
source

All Articles