How to like a Facebook page on android?

1.1k Views Asked by At

I have managed to "Like" a non-Facebook webpage, but when I try Liking a Facebook one, using OpenGraph, I get: Like actions are not yet supported against objects of this type.

Is there any way to like a Facebook page using the Android Facebook SDK, not using a WebView?

2

There are 2 best solutions below

1
On

You can't directly like page. You will have to show that page in webView or native app. Then user will have to press like manually... It works like this to prevent manipulations on Fb counters.

1
On

I assumes you have knowledge of developing app in facebook developer site. get your app id and paste id String resources.

xxxxxxxxxxxxxx

change your manifest.

///////////////////////////////Activity_main////////////////////

<com.facebook.widget.LikeView
        android:id="@+id/like_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        facebook:confirm_logout="false"
        facebook:fetch_user_info="true" />

/////////////////////////////////////////////Main Activity//////////////////

package com.example.loginfacebook;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.facebook.widget.LikeView;

public class MainActivity extends FragmentActivity {
    private LikeView like;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        like = (LikeView) findViewById(R.id.like_view);


        like.setObjectId("https://www.facebook.com/appbellfitness");

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //uiHelper.onActivityResult(requestCode, resultCode, data);

        LikeView.handleOnActivityResult(getApplicationContext(), requestCode, resultCode, data);
    }



}

thats it... note(facebook doesnot allow directly like a page on native android button click.)