像按钮的facebook显示单击时的空白页面

时间:2014-12-20 08:29:44

标签: java android facebook facebook-graph-api

您好我一直试图在我的Android应用程序上放置像butto这样的脸书,以便用户可以点击我的Facebook页面。

我想我已按照https://developers.facebook.com/docs/android/like-button/

中的facebook开发者页面的指示完成了所有操作

但是点击“赞”按钮后,该应用会显示一个空白页面,然后再次返回应用。以下是我一直在使用的代码

这是我使用的布局的一部分:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:contentDescription="@string/logo"
        android:padding="10dp"
        android:src="@drawable/nrnlogo" />

    <com.facebook.widget.LikeView
        android:id="@+id/like_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp" />
</LinearLayout>
</LinearLayout>

MainActivity.java如下。 我将不得不在MainActivity.java

中放置的片段中实现它
public static class HomeFragment extends Fragment{
    public static final String ARG_CATEGORY_NUMBER = "category_number";
    private UiLifecycleHelper uiHelper;
    public int currentimageindex = 0;
    private SwipeRefreshLayout swipeLayout;
    //private Callback callback;

    public HomeFragment() {
        // Empty constructor required for fragment subclasses
    }

    @SuppressWarnings("deprecation")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home, container,
                false);

        //SWIPE TO REFRESH
        swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container);
        //swipeLayout.setOnRefreshListener((OnRefreshListener) getActivity());
        swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);

      //SWIPE TO REFRESH
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeLayout.setRefreshing(true);
                Log.d("Swipe", "Refreshing Number");
                ( new Handler()).postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        swipeLayout.setRefreshing(false);
                        double f = Math.random();
                    }
                }, 3000);
            }
        });

        // FACEBOOK LIKE BUTTON
        Settings.sdkInitialize(getActivity());
        //uiHelper = new UiLifecycleHelper(this.getActivity(), null);
        LikeView likeView = (LikeView) rootView
                .findViewById(R.id.like_view);
        likeView.setObjectId("http://www.facebook.com/NewsNrnDotCom");
        //likeView.setForegroundColor(-256);

        ListView hlvCategory = (ListView) rootView
                .findViewById(R.id.group_content);
        Log.e("Adapter Set Vertical", "ABC");
        AdView mAdView = (AdView) rootView.findViewById(R.id.adView);
        HomeJsonData hjd = new HomeJsonData(getActivity(), hlvCategory,
                mAdView, mDrawerList);

        hjd.execute();

    // FACEBOOK LIKE BUTTON
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LikeView.handleOnActivityResult(getActivity(), requestCode, resultCode, data);
        //uiHelper.onActivityResult(requestCode, resultCode, data, null);
    }
}

谁能告诉我我犯了什么错误?

1 个答案:

答案 0 :(得分:1)

您是否在为自己的应用使用FB测试用户帐户?测试帐户不允许像页面一样。我有同样的问题。我改为使用我的实际FB帐户,LikeButton工作得很好