I want to integrate a like button in my android app. I used the code
likeWebView = (WebView) findViewById( R.id.webView1 );
likeWebView.getSettings().setJavaScriptEnabled(true);
String url = "http://www.facebook.com/plugins/like.php?" +
"href=" + URLEncoder.encode("likeurl" ) + "&" +
"layout=standard&" +
"show_faces=false&" +
"width=500&" +
"action=like&" +
"colorscheme=light&" +
"access_token=" + URLEncoder.encode( "read_stream" );
likeWebView.loadUrl( url );
But after login it is showing a blank page. Please give me a solution to add a Like button.
Your Facebook page will not be banned for buying Facebook likes. Facebook's terms of service don't actually prohibit buying likes. They do try to ban fake accounts, however. If a big number of your likes are fake, you'll lose them if Facebook catches them and bans their accounts.
Finally Facebook and Launched Like Button for Android
Steps:
1 - Add Facebook Library to Project
2 - Create App on Facebook 3 - Update Manifest
**In the Application tab add meta-data**
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/fb_id" />
4 - Add LikeView in Layout
//activitymain.xml
<com.facebook.widget.LikeView
android:id="@+id/like_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</com.facebook.widget.LikeView>
5 - ActivityMain.java
//set facebook page or link to this like button
LikeView likeView;
UiLifecycleHelper uiHelper;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
uiHelper = new UiLifecycleHelper(this, null);
likeView = (LikeView) findViewById(R.id.like_view);
likeView.setObjectId("https://www.facebook.com/<page_username>");//it can be any link
likeView.setLikeViewStyle(LikeView.Style.STANDARD);
likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.LEFT);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data, null);
}
Output
private initLikeButton( String urlToLike ) {
likeWebView = (WebView) findViewById( R.id.likeWebView );
likeWebView.getSettings().setJavaScriptEnabled(true);
String url = "http://www.facebook.com/plugins/like.php?" +
"href=" + URLEncoder.encode( urlToLike ) + "&" +
"layout=standard&" +
"show_faces=false&" +
"width=375&" +
"action=recommend&" +
"colorscheme=light&" +
"access_token=" + URLEncoder.encode( FacebookAdapter.getInstance().getAccessToken() );
likeWebView.loadUrl( url );
Here, in your code you must be put likeurl , url that like.
using the iframe code provided by the like button code generator at http://developers.facebook.com/docs/reference/plugins/like. But since an iframe is basically the same thing as a WebView, it seemed redundant to load the code in an iframe and then load the iframe in a WebView. So instead I just loaded the code that would be in the iframe directly into the WebView using the code below. But the same thing happens either way.
Incidentally, the same issue exists when developing an iPhone app. We don't want the user to have to login to facebook every time they run our app. But unfortunately, if the user has logged into facebook on another computer since the last time they logged into facebook via our app, they'll have to log in again.
On the android platform I would think a better solution might be to have a facebook app that you send an intent to that takes care of keeping the user logged in and returning the html for rendering the like button.
see more: https://github.com/facebook/facebook-android-sdk/issues/17
http://blog.doityourselfandroid.com/2011/02/28/30-minute-guide-integrating-facebook-android-application/
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
integrate facebook with like button in android and iphone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With