Suraj
Suraj

Reputation: 586

Facebook like button shows blank popup and returns nothing on android application

I have developed an android application which has Facebook like button using Facebook SDK from android like button. But when we click on like button it shows blank popup and returns back on screen. Also like is not working.

below is code.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Settings.sdkInitialize(this);

        uiHelper = new UiLifecycleHelper(this, null);
        uiHelper.onCreate(savedInstanceState);

        likeView  = (LikeView) findViewById(R.id.like_view);
        likeView.setObjectId("https://www.facebook.com/VehicleDocs");

        likeView.setLikeViewStyle(LikeView.Style.BUTTON);
        likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
        likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.CENTER);

        share = (Button)findViewById(R.id.share);
        share.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(MainActivity.this)
                .setLink("https://www.facebook.com/rkvb")
                .build();
                uiHelper.trackPendingDialogCall(shareDialog.present());

            }
        });
 }

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        // uiHelper.onActivityResult(requestCode, resultCode, data, null);
            // if you don't use the UiLifecycleHelper, call handleOnActivityResult on the LikeView instead
            // LikeView.handleOnActivityResult(this, requestCode, resultCode, data);
         //  Log.i("count", "OnActivityResult...");


             uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
                 @Override
                 public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
                     Log.e("Activity", String.format("Error: %s", error.toString()));
                 }

                 @Override
                 public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
                     Log.i("Activity", "Success!");
                 }
             });
}

activity_main.xml

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

        android:layout_below="@+id/textView1"
        android:layout_marginTop="116dp" 

        >
    </com.facebook.widget.LikeView>

Upvotes: 2

Views: 1122

Answers (1)

Harsh Patel
Harsh Patel

Reputation: 101

Are you using the FB test user account for login in your app? Test accounts are not allowed to Like a page. I had the same problem. I changed to using my actual FB account for login and the LikeButton worked perfectly fine!

Upvotes: 1

Related Questions