ganesh
ganesh

Reputation: 131

Facebook like Button with user authentication

I am developing a ipad application in that i need to include facebook page like button. I have loaded the button using iframe in webview, when user clicked on the button if they already sigh in just count should increment or decrement else pop up will ask them to login first. once they logged in then increment the count automatically.
Any sample for code to do step by step.

Here is my webview like button code

NSString *likeButtonIframe = @"<iframe src='http://www.facebook.com/plugins/likebox.php?id=XXXXXXXXXXXXXXX&amp;width=292&amp;connections=0&amp;stream=false&amp;header=false&amp;height=62' scrolling='no' frameborder=0' style='border:none; overflow:hidden; width:282px; height:62px;' allowTransparency='true'></iframe>";

NSString *likeButtonHtml = [NSString stringWithFormat:@"<HTML><BODY>%@</BODY></HTML>", likeButtonIframe];
[_webView loadHTMLString:likeButtonHtml baseURL:[NSURL URLWithString:@""]];

Also i have tried before shows like i will ask him to login first then display the like button and ask them to like.

Upvotes: 0

Views: 1692

Answers (2)

Neil Galiaskarov
Neil Galiaskarov

Reputation: 5073

I used UIWebView's delegate method

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

to detect when user does not have active session. Here is my sample code: https://github.com/gneil90/facebook-likebox-ios-login

Upvotes: 1

vishy
vishy

Reputation: 3231

As per Facebook you should not have a like button in the app, that is to avoid spam likes.

Even through we can implement it using iFrame & UIWebView.

RayWinderlich has a great tutorial for this Facebook Like Button in iOS app.

Follow this link to generate a Facebook like frame for your page.

And use accordingly in your app, one limitation is that if user is not logged in it shows a login screen within it. So if your webView is small, it will be issue. Check out the sample from tutorial, and implement as per your requirements.

Upvotes: 0

Related Questions