Facebook Like button in Android Application

后端 未结 6 1366
执笔经年
执笔经年 2020-12-14 12:35

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://w         


        
6条回答
  •  情话喂你
    2020-12-14 13:30

    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

          
            
    

    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.

提交回复
热议问题