Facebook Like button in Android Application
Asked Answered
C

6

7

I want to display like button in my android application. Below is the code I use to display a Like button in my android application.

String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://beta.demo.dy/web/service/304.htm"
webview = (WebView) findViewById(R.id.webView1);
webview.loadUrl(url);
webview.setWebViewClient(new LikeWebviewClient());

public class LikeWebviewClient  extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

But when I run this application it displays a white area. How to resolve this?

Collar answered 17/10, 2011 at 13:44 Comment(2)
hey I want to do the same thing. please tell me is it solved ? if yes then how have you done it ?Blancheblanchette
You can add the webview in that set the height and width of the webview.so that onlu like button is displayed to the user.Collar
R
4

Facebook SDK hasn't provided like button feature for native mobile apps( As of Oct 17 2011). It is available in Mobile Web apps. For more info you can check out these link:
Mobile - Facebook Developers
Like Button - Facebook Developers

Rabblerousing answered 17/10, 2011 at 14:3 Comment(1)
i want to dispaly that in Webview of android.it is possible in ios they also disaply webview of like button so i want to thatCollar
P
7

The like option can be implemented easily on Native platform languages(Android, iOS) as well as browsers (curl, PHP, JavaScript) as follows. Go to developer.facebook app section and within the Open Graph section of the Developer App configuration, add the built-in Like action, which should appear in the drop-down when adding a new Open Graph action. Refer here for latest updates.

Once done, Select "Get Code" option to retrieve sample code as depicted below for Android platform. You can choose platform of your choice. Note that app_specific_unique_identifier is uniquee for apps, i have removed it for security reasons and you have to use the one for your app.

I have been able to test the Like flow successfully. Hope this helps.

Bundle params = new Bundle();
params.putString("object", "http://samples.ogp.me/<app_specific_unique_identifier>");

Request request = new Request(
    Session.getActiveSession(),
    "me/og.likes",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response
Purveyance answered 10/2, 2013 at 1:36 Comment(2)
this is a great answer. I've been searching for such an answer for three days in a row. Thanks a lot!Hooghly
I don't have the option for a built-in (common) like action. Any suggestions?Anse
R
4

Facebook SDK hasn't provided like button feature for native mobile apps( As of Oct 17 2011). It is available in Mobile Web apps. For more info you can check out these link:
Mobile - Facebook Developers
Like Button - Facebook Developers

Rabblerousing answered 17/10, 2011 at 14:3 Comment(1)
i want to dispaly that in Webview of android.it is possible in ios they also disaply webview of like button so i want to thatCollar
J
3

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 enter image description here

Joycejoycelin answered 28/11, 2014 at 22:1 Comment(1)
Is there a way to like the application itself? Just like the Google plus one button in Google Play.Meadows
T
2

You can use facebook like button in android app using special permission from facebook developer account https://developers.facebook.com. Add your app here and submit app special permission. Go to app review and submit items for approval. click on start submission and after that select LIKE native button and submit all details they want like why you want get like permission , how your app will use this permission everything. If Facebook will approve your request then you can use facebook like button inside app.enter code here

      <com.facebook.share.widget.LikeView
         android:id="@+id/facebooklike"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
        </com.facebook.share.widget.LikeView>

After this you need to do some java code.

likeView = (LikeView) findViewById(R.id.facebooklike);
    likeView.setLikeViewStyle(LikeView.Style.STANDARD);            
   likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
    likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.CENTER);
    likeView.setObjectIdAndType("url of like page", LikeView.ObjectType.PAGE);

like functionality automatically call when you click on like button.

now you need to get response from like page that user like that page of unlike that page.

enter code here

public class FbLikes extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fb_likes);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {
        if (resultCode == RESULT_OK) {
            // verify we're returning from like action
                // get action results
                bundle = data.getExtras().getBundle("com.facebook.platform.protocol.RESULT_ARGS");
                if (bundle != null) {
                    like = bundle.getBoolean("object_is_liked");// liked/unliked
                    bundle.getInt("didComplete");
                    bundle.getInt("like_count"); // object like count
                    bundle.getString("like_count_string");
                    bundle.getString("social_sentence");
                    bundle.getString("completionGesture"); // liked/cancel/unliked
                    Log.e(TAG, bundle.getString("social_sentence") + "");
                    Log.e(TAG, "likeornot" + bundle.getBoolean("object_is_liked") + "");
                    Log.e(TAG, "lcomplete" + bundle.getString("completionGesture") + "");
                    Log.e(TAG, "count" + bundle.getInt("like_count") + "");
                    Log.e(TAG, "countstr" + bundle.getString("like_count_string") + "");
                    Log.e(TAG, "did" + bundle.getInt("didComplete") + "");
                }
        }
    } catch (Exception e) {

    }
}

} this code will return everything you want from like functionality.

Tot answered 9/5, 2017 at 13:21 Comment(0)
H
0

Try this one i made some modification

String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://beta.demo.dy/web/service/304.htm";
                 //   webview = (WebView) findViewById(R.id.webview);
                    webView.loadUrl(url);
                     webView.setWebViewClient(new WebViewClient());
                 class LikeWebviewClient  extends WebViewClient
                    {
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            view.loadUrl(url);
                            return true;
                        }
                    }
Hakenkreuz answered 27/7, 2012 at 11:0 Comment(0)
C
0

Facebook has recently provided the feature of likebutton in facebook sdk 3.21.1. You can go through these links to download sdk and tutorial for implementation of likebutton.

Download SDK: http://developers.facebook.com/docs/android

Tutorial http://developers.facebook.com/docs/android/like-button

I hope it may solve your problem.

Creighton answered 18/12, 2014 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.