在facebook登录时没有调用活动结果方法

时间:2014-11-29 06:52:54

标签: android

我已经返回以下代码,但在登录Facebook后我没有获得我的用户名。他们的logcat中也没有出现错误。

package com.example.mindwareuae;




import java.util.Arrays;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.InputFilter.LengthFilter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;



import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphUser;
import com.facebook.widget.LoginButton;
import com.facebook.widget.LoginButton.UserInfoChangedCallback;

public class FacebokkFragment extends Fragment {
    private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");


    View rootView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


         rootView = inflater.inflate(R.layout.fragment_facebook,container,false);
         Session.openActiveSession(getActivity(), true, new Session.StatusCallback() {


              @Override
              public void call(Session session, SessionState state, Exception exception) {
                if (session.isOpened()) {
                    Toast.makeText(getActivity(), session.getAccessToken(), 1000).show();

                  Request.newMeRequest(session, new Request.GraphUserCallback() {

                    // callback after Graph API response with user object
      @Override
                    public void onCompleted(GraphUser user, Response response)
      {
                      if (user != null) {
                        TextView welcome = (TextView) rootView.findViewById(R.id.textView1);
                        welcome.setText("Hello " + user.getName() + "!");

                      }
                    }
                  }).executeAsync();
                }
              }
            });
        return rootView;
    }
         protected void requestPermissions() {
        // TODO Auto-generated method stub
             Session s = Session.getActiveSession();


    }
        protected boolean checkPermissions() {
        // TODO Auto-generated method stub

            Session s = Session.getActiveSession();
            if (s != null) {
                return s.getPermissions().contains("publish_actions");
            } else
                return false;

    }
        @Override
          public void onActivityResult(int requestCode, int resultCode, Intent data) {
              super.onActivityResult(requestCode, resultCode, data);
              Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data);
          }

}

在这个我需要用用户名显示你好, 任何人都可以解释我 感谢adavnce

0 个答案:

没有答案