public void initialize(LoginButton fbLoginBtn, CallbackManager callbackManager) {

    // Setting permissions for fetching facebook content and performing facebook actions (eg:
    // posting on facebook)
    List<String> facebookPermissions =
        Arrays.asList(
            "user_photos", "email", "user_birthday", "user_friends", "read_custom_friendlists");
    fbLoginBtn.setReadPermissions(facebookPermissions);

    // Callback registration
    fbLoginBtn.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Toast.makeText(context, "Success", Toast.LENGTH_LONG).show();
          }

          @Override
          public void onCancel() {
            Toast.makeText(context, "Failed", Toast.LENGTH_LONG).show();
          }

          @Override
          public void onError(FacebookException exception) {
            Toast.makeText(context, "Error", Toast.LENGTH_LONG).show();
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this);
    setContentView(R.layout.activity_log_in);

    // setViewObject();
    // setListner();

    callbackManager = CallbackManager.Factory.create();
    // LoginButtonはFacebookSDKに含まれたButtonウィジェットの拡張ウィジェット。
    loginButton = (LoginButton) findViewById(R.id.login_btn_facebook);
    // APIから取得したいユーザー情報の種類を指定し、パーミッションを許可する。
    List<String> permissionNeeds =
        Arrays.asList("user_photos", "email", "user_birthday", "public_profile");
    loginButton.setReadPermissions(permissionNeeds);

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            System.out.println("");
            GraphRequest request =
                GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                      @Override
                      public void onCompleted(JSONObject object, GraphResponse response) {
                        // API連携に成功し、ログイン状態になったら、下記のようなゲッター関数により、ユーザー情報を取得することが出来る。
                        try {
                          String id = object.getString("id");
                          String name = object.getString("name");
                          String email = object.getString("email");
                          String gender = object.getString("gender");
                          String birthday = object.getString("birthday");
                          System.out.println(name);
                        } catch (JSONException e) {
                          e.printStackTrace();
                        }
                      }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,gender, birthday");
            request.setParameters(parameters);
            request.executeAsync();
          }

          @Override
          public void onCancel() {
            System.out.println("onCancel");
          }

          @Override
          public void onError(FacebookException exception) {
            Log.v("LoginActivity", exception.toString());
          }
        });
  }
 @Override
 public void onViewCreated(View view, Bundle savedInstanceState) {
   super.onViewCreated(view, savedInstanceState);
   LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
   loginButton.setReadPermissions("user_friends");
   loginButton.setFragment(this);
   loginButton.registerCallback(mCallbackManager, mCallback);
 }
  public void signInWithFaceButton(LoginButton loginButton) {
    List<String> permissionNeeds = Arrays.asList("email", "user_about_me");
    loginButton.setReadPermissions(permissionNeeds);
    loginButton.registerCallback(
        mCallbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {

            GraphRequest request =
                GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                      @Override
                      public void onCompleted(JSONObject object, GraphResponse response) {
                        Log.v("TAG", "JSON: " + object);
                        try {
                          String id = object.getString("id");
                          String foto =
                              "https://graph.facebook.com/" + id + "/picture?height=120&width=120";
                          String nome = object.getString("name");
                          String email = object.getString("email");
                          if (mFaceCallback != null) {
                            mFaceCallback.getInfoFace(id, nome, email, foto);
                          } else {
                            throw new IllegalArgumentException(
                                "interface InfoLoginFaceCallback is null");
                          }
                        } catch (JSONException e) {
                          e.printStackTrace();
                        }
                      }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,picture.width(120).height(120)");
            request.setParameters(parameters);
            request.executeAsync();
          }

          @Override
          public void onCancel() {
            if (mFaceCallback != null) {
              mFaceCallback.cancelLoginFace();
            } else {
              throw new IllegalArgumentException("interface InfoLoginFaceCallback is null");
            }
          }

          @Override
          public void onError(FacebookException error) {
            if (mFaceCallback != null) {
              mFaceCallback.erroLoginFace(error);
            } else {
              throw new IllegalArgumentException("interface InfoLoginFaceCallback is null");
            }
          }
        });
  }
Beispiel #5
0
  // what happens when the view is created
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // find fb login button by id and assign it to variable
    LoginButton login_button = (LoginButton) view.findViewById(R.id.login_button);
    login_button.setFragment(this); // set login button as a fragment

    login_button.registerCallback(callBackManager, callback); // register callback to button
  }
Beispiel #6
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    btnConnectWithFacebook = (LoginButton) getActivity().findViewById(R.id.btnConnectWithFacebok);
    btnConnectWithFacebook.setTypeface(
        FontManager.setFont(getActivity(), FontManager.Font.OpenSansSemiBold));

    btnConnectWithFacebook.setReadPermissions(Arrays.asList("public_profile, email"));
    btnConnectWithFacebook.setFragment(this);
    btnConnectWithFacebook.registerCallback(callbackManager, callback);
  }
  @Test
  public void testCantSetPublishThenReadPermissions() throws Exception {
    Activity activity = Robolectric.buildActivity(MainActivity.class).create().get();

    LoginButton loginButton = (LoginButton) activity.findViewById(R.id.login_button);
    loginButton.setPublishPermissions("publish_actions");
    try {
      loginButton.setReadPermissions("user_location");
    } catch (UnsupportedOperationException e) {
      return;
    }
    fail();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // initializing facebook sdk
    FacebookSdk.sdkInitialize(getApplicationContext());

    // setting layout
    setContentView(R.layout.activity_login);

    // binding id's to view
    ButterKnife.bind(this);

    // facebook login button
    fbLoginButton.setReadPermissions("user_friends", "public_profile");

    // initializing callback function
    callbackManager = CallbackManager.Factory.create();

    // Callback registration
    fbLoginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            // App code
            //                getUserDetail();
            //                Intent goToNavigation = new Intent(LoginActivity.this,
            // NavigationDrawerActivity.class);
          }

          @Override
          public void onCancel() {
            Snackbar.make(
                    fbLoginButton,
                    "Can not login using Facebook, Please try logging again or Enter application without logging in",
                    Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }

          @Override
          public void onError(FacebookException exception) {
            Snackbar.make(fbLoginButton, "Some Error occurred! Login again", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });
  }
  @Test
  public void testLoginButtonWithPublishPermissions() throws Exception {
    LoginManager loginManager = mock(LoginManager.class);
    Activity activity = Robolectric.buildActivity(MainActivity.class).create().get();

    LoginButton loginButton = (LoginButton) activity.findViewById(R.id.login_button);
    ArrayList<String> permissions = new ArrayList<>();
    permissions.add("publish_actions");
    loginButton.setPublishPermissions(permissions);
    loginButton.setLoginManager(loginManager);
    loginButton.performClick();

    verify(loginManager, never()).logInWithReadPermissions(isA(Activity.class), anyCollection());
    verify(loginManager).logInWithPublishPermissions(activity, permissions);
  }
Beispiel #10
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // mTextDisplayed = (TextView) view.findViewById(R.id.text_details);

    // Create facebook button and initialize permissions.
    fbLoginButton = (LoginButton) view.findViewById(R.id.login_button);
    fbLoginButton.setPublishPermissions("publish_actions");
    fbLoginButton.setFragment(this);
    fbLoginButton.registerCallback(mCallbackManager, facebookCallback);

    // Creating loginButton and setting the callback.
    twitterLoginButton = (TwitterLoginButton) view.findViewById(R.id.twitter_login_button);
    twitterLoginButton.setCallback(twitterSessionCallback);
  }
Beispiel #11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
    mClient.connect();

    Intent sIntent = new Intent(this, BeeplePaperService.class);
    startService(sIntent);

    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_main);

    final Button btn = (Button) findViewById(R.id.mButt);

    btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent mIntent = new Intent(Intent.ACTION_SEND);
            sendBroadcast(mIntent);
          }
        });

    callbackManager = CallbackManager.Factory.create();
    Log.d(TAG, "Building login button for FB");
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("user_friends");
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "Getting access token");
          }

          @Override
          public void onCancel() {
            Log.d(TAG, "Login Cancelled");
          }

          @Override
          public void onError(FacebookException exception) {
            Log.e(TAG, exception.toString());
          }
        });
  }
  public void onResume() {
    super.onResume();

    // Load layout
    btnLogin = (LoginButton) findViewById(R.id.btnLogin);

    // Check if user is already logged in to Facebook with this app
    if (FacebookController.getInstance(this).isLoggedIn()) {
      writeProfileToPrefs(Profile.getCurrentProfile());
      onLoginSuccessful();
    }

    callbackManager = CallbackManager.Factory.create();
    btnLogin.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            writeProfileToPrefs(Profile.getCurrentProfile());
            onLoginSuccessful();
          }

          @Override
          public void onCancel() {
            Toast.makeText(LoginActivity.this, R.string.login_cancelled, Toast.LENGTH_LONG).show();
          }

          @Override
          public void onError(FacebookException exception) {
            Toast.makeText(LoginActivity.this, R.string.login_failed, Toast.LENGTH_LONG).show();
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    callbackManager = CallbackManager.Factory.create();

    setContentView(R.layout.activity_main);
    info = (TextView) findViewById(R.id.info);
    loginButton = (LoginButton) findViewById(R.id.login_button);

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            info.setText(
                "User ID: "
                    + loginResult.getAccessToken().getUserId()
                    + "\n"
                    + "Auth Token: "
                    + loginResult.getAccessToken().getToken());
          }

          @Override
          public void onCancel() {
            info.setText("Login attempt canceled.");
          }

          @Override
          public void onError(FacebookException error) {
            info.setText("Login attempt failed.");
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_main);
    nameText = (TextView) findViewById(R.id.text_name);
    dataList = (ListView) findViewById(R.id.list_data);
    contentButton = (Button) findViewById(R.id.content_button);
    fbbutton = (LoginButton) findViewById(R.id.login_button);

    fbbutton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onFblogin();
          }
        });
    if (AccessToken.getCurrentAccessToken() != null) {
      contentButton.setVisibility(View.VISIBLE);
      contentButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              access_token = AccessToken.getCurrentAccessToken();
              getFacebookData();
            }
          });
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    Firebase.setAndroidContext(this);
    setContentView(R.layout.activity_main);
    ref = new Firebase("https://amber-fire-4138.firebaseio.com");

    callbackManager = CallbackManager.Factory.create();
    setContentView(R.layout.activity_main);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            onFacebookAccessTokenChange(loginResult.getAccessToken());
            // App code
          }

          @Override
          public void onCancel() {
            // App code
          }

          @Override
          public void onError(FacebookException exception) {
            // App code
          }
        });
  }
Beispiel #16
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);

    SignInButton button = (SignInButton) findViewById(R.id.google_login);
    button.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            pickUserAccount();
          }
        });

    callbackManager = CallbackManager.Factory.create();
    fbButton = (LoginButton) findViewById(R.id.facebook_login);

    fbButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Log.d("LoginActivity", loginResult.getAccessToken().getToken());
            mBoundService.sendJOIN("fb", loginResult.getAccessToken().getToken());
          }

          @Override
          public void onCancel() {}

          @Override
          public void onError(FacebookException error) {}
        });
  }
Beispiel #17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);

    callbackManager = CallbackManager.Factory.create();
    googleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

    LoginButton loginButton = (LoginButton) findViewById(R.id.activity_login_facebook);
    googleSignIn = (SignInButton) findViewById(R.id.activity_login_google);
    getToken = (Button) findViewById(R.id.activity_login_auth_token);

    loginButton.setReadPermissions("email");

    facebookTokenTracker =
        new AccessTokenTracker() {
          @Override
          protected void onCurrentAccessTokenChanged(
              AccessToken oldAccessToken, AccessToken newAccessToken) {
            isFbLogin = true;
            Toast.makeText(LoginActivity.this, "Facebook Access Token", Toast.LENGTH_SHORT).show();
          }
        };

    facebookProfileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) {
            isFbLogin = (!isFbLogin);
            Toast.makeText(LoginActivity.this, "Facebook Current Profile", Toast.LENGTH_SHORT)
                .show();
          }
        };

    facebookTokenTracker.startTracking();
    facebookProfileTracker.startTracking();
    googleSignIn.setOnClickListener(this);
    getToken.setOnClickListener(this);
  }
Beispiel #18
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    loginButton = (LoginButton) view.findViewById(R.id.ivfb);
    tvUser = (TextView) getView().findViewById(R.id.tvUser);
    etEmail = (EditText) getView().findViewById(R.id.etEmail);
    etUser = (EditText) getView().findViewById(R.id.etUser);
    etPhone = (EditText) getView().findViewById(R.id.etPhone);
    etPass = (EditText) getView().findViewById(R.id.etPass);
    bLogin = (Button) view.findViewById(R.id.bLogin);
    bReg = (Button) view.findViewById(R.id.bReg);
    ivgp = (ImageView) view.findViewById(R.id.ivgp);

    loginButton.setReadPermissions("user_friends");
    loginButton.setFragment(this);
    loginButton.registerCallback(callbackManager, callback);
  }
  public void onResume() {
    super.onResume();

    if (isLoggedIn()) {
      loginButton.setVisibility(View.INVISIBLE);
      Profile profile = Profile.getCurrentProfile();
      homeFragment(profile);
    }
  }
  @Test
  public void testLoginButtonWithReadPermissions() throws Exception {
    LoginManager loginManager = mock(LoginManager.class);
    Activity activity = Robolectric.buildActivity(MainActivity.class).create().get();

    LoginButton loginButton = (LoginButton) activity.findViewById(R.id.login_button);
    ArrayList<String> permissions = new ArrayList<>();
    permissions.add("user_location");
    loginButton.setReadPermissions(permissions);
    loginButton.setDefaultAudience(DefaultAudience.EVERYONE);
    loginButton.setLoginManager(loginManager);
    loginButton.performClick();

    verify(loginManager).logInWithReadPermissions(activity, permissions);
    verify(loginManager, never()).logInWithPublishPermissions(isA(Activity.class), anyCollection());
    // Verify default audience is channeled
    verify(loginManager).setDefaultAudience(DefaultAudience.EVERYONE);
  }
Beispiel #21
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    callbackManager = CallbackManager.Factory.create();

    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile");

    // Callback registration
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            updateDatabase();
            // jump to another activity
            Intent showPosts = new Intent(LoginActivity.this, PostActivity.class);
            startActivity(showPosts);
          }

          @Override
          public void onCancel() {
            showAlert();
          }

          @Override
          public void onError(FacebookException exception) {
            showAlert();
          }

          private void showAlert() {
            new AlertDialog.Builder(LoginActivity.this)
                .setTitle(R.string.cancelled)
                .setMessage(R.string.login_failed)
                .setPositiveButton(R.string.ok, null)
                .show();
          }
        });

    LoginManager.getInstance()
        .logInWithReadPermissions(this, Collections.singletonList("public_profile"));
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_main);

    callbackManager = CallbackManager.Factory.create();

    final LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile", "email", "user_friends");

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {

          @Override
          public void onSuccess(LoginResult loginResult) {

            Intent intent = new Intent(MainActivity.this, HomeActivity.class);
            startActivity(intent);

            System.out.print("Logged in");
          }

          @Override
          public void onCancel() {
            // App code
          }

          @Override
          public void onError(FacebookException exception) {
            Toast.makeText(
                    MainActivity.this, "Error al realizar Login Facebook", Toast.LENGTH_SHORT)
                .show();
            Log.i("Error", "Error");
          }
        });

    // printHashKey();

  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.splash, container, false);

    callbackManager = CallbackManager.Factory.create();
    loginButton = (LoginButton) view.findViewById(R.id.login_button);
    loginButton.setReadPermissions("user_friends");
    loginButton.setFragment(this);
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Toast.makeText(getActivity(), "Login successful", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onCancel() {
            Toast.makeText(getActivity(), "Login canceled", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onError(FacebookException exception) {
            Toast.makeText(getActivity(), "Login error", Toast.LENGTH_SHORT).show();
          }
        });

    skipLoginButton = (TextView) view.findViewById(R.id.skip_login_button);
    skipLoginButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (skipLoginCallback != null) {
              skipLoginCallback.onSkipLoginPressed();
            }
          }
        });

    return view;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebook_login);
    // Initialise facebook SDK
    FacebookSdk.sdkInitialize(getApplicationContext());
    mCallbackManager = CallbackManager.Factory.create();

    mCircularImageView = (CircularImageView) findViewById(R.id.imageView);
    txtName = (TextView) findViewById(R.id.txt_name);
    //        txtDOB = (TextView) findViewById(R.id.txt_dob);
    txtName.setText("this is sample text");
    mLoginButton = (LoginButton) findViewById(R.id.login_button);
    mLoginButton.setReadPermissions("user_friends");

    LoginManager.getInstance()
        .registerCallback(
            mCallbackManager,
            new FacebookCallback<LoginResult>() {
              @Override
              public void onSuccess(LoginResult loginResult) {
                updateUI();
              }

              @Override
              public void onCancel() {
                Log.v(logString, "Login cancle");
              }

              @Override
              public void onError(FacebookException error) {

                Log.e(logString, "error");
                error.printStackTrace();
              }
            });

    profileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            Log.v(logString, "onCurrentProfileTracker");
            updateUI();
          }
        };

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_log_in);

    callbackManager = CallbackManager.Factory.create();
    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Log.d("debug", loginResult.getAccessToken().getToken());
            AccessToken accessToken = loginResult.getAccessToken();

            GraphRequest.newMeRequest(
                    accessToken,
                    new GraphRequest.GraphJSONObjectCallback() {
                      @Override
                      public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                        Log.d("debug", "me request: " + jsonObject.toString());
                      }
                    })
                .executeAsync();

            GraphRequest.newGraphPathRequest(
                    accessToken,
                    "/me?fields=feed",
                    new GraphRequest.Callback() {
                      @Override
                      public void onCompleted(GraphResponse graphResponse) {
                        String response = graphResponse.getRawResponse();
                        Log.d("debug", "graph path request: " + response);
                      }
                    })
                .executeAsync();
          }

          @Override
          public void onCancel() {}

          @Override
          public void onError(FacebookException e) {
            e.printStackTrace();
          }
        });
  }
Beispiel #26
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(this.getApplicationContext());
    requestWindowFeature(Window.FEATURE_NO_TITLE); // hide title
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN); // hide top bar
    setContentView(R.layout.highscorescreen);

    btn_back = (Button) findViewById(R.id.btn_back);
    btn_back.setOnClickListener(this);

    theScore = getSharedPreferences("thePref", Context.MODE_PRIVATE);
    theText = (TextView) findViewById(R.id.textView);
    theText.setText("" + theScore.getInt("HighScore", 0));

    callbackManager = CallbackManager.Factory.create();

    List<String> PERMISSIONS = Arrays.asList("publish_actions");

    loginBtn = (LoginButton) findViewById(R.id.fb_login_button);
    loginManager = LoginManager.getInstance();
    loginManager.logInWithPublishPermissions(this, PERMISSIONS);

    loginBtn.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {

          @Override
          public void onSuccess(LoginResult loginResult) {

            sharePhotoToFacebook();
          }

          @Override
          public void onCancel() {
            userName.setText("Login attempt canceled.");
          }

          @Override
          public void onError(FacebookException e) {
            userName.setText("Login attempt failed.");
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Iniciar Parse
    Parse.initialize(
        this,
        getResources().getString(R.string.parseId),
        getResources().getString(R.string.parseKey));
    localRepository = new ParseLocalRepository();
    camareroRepository = new ParseCamareroRepository();
    cocinaRepository = new ParseCocinaRepository();
    extraRepository = new ParseExtraRepository();

    // iniciar Facebook
    FacebookSdk.sdkInitialize(getApplicationContext());

    // Hay que cargar la api de facebook antes de ejecutar el setContextView para que importe el
    // boton estilo facebook
    setContentView(R.layout.activity_main);

    callbackManager = CallbackManager.Factory.create();

    loginButton = (LoginButton) findViewById(R.id.login_button);

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            user = new Usuario(loginResult.getAccessToken().getUserId());

            AccessToken accessToken = loginResult.getAccessToken();
            profile = Profile.getCurrentProfile();
          }

          @Override
          public void onCancel() {
            Toast.makeText(getBaseContext(), "Inicio de sesion cancelado", Toast.LENGTH_SHORT)
                .show();
          }

          @Override
          public void onError(FacebookException e) {
            Toast.makeText(getBaseContext(), "Inicio de sesion fallido", Toast.LENGTH_SHORT).show();
          }
        });
  }
Beispiel #28
0
  public void setUpFriendListPage() {
    if (utils.getProfilePic() != null) {
      profileImage.setBackground(utils.getProfilePic());
    } else {
      profileImage.setBackgroundResource(R.mipmap.fb_logo);
    }
    profileImage.setVisibility(View.VISIBLE);
    userInfo.setVisibility(View.VISIBLE);
    backButtons.setVisibility(View.VISIBLE);

    btnSyncContacts.setVisibility(View.INVISIBLE);
    logo.setVisibility(View.INVISIBLE);
    info.setVisibility(View.INVISIBLE);
    orText.setVisibility(View.INVISIBLE);
    loginButton.setVisibility(View.INVISIBLE);

    // TODO display friend list
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // for finding key hash of dev environment
    // Log.i(TAG, printKeyHash(this));
    pref = getSharedPreferences(Constants.SHARED_PREFERENCE, Context.MODE_PRIVATE);
    // initializing facebook sdk
    FacebookSdk.sdkInitialize(this.getApplicationContext());

    // setting the layout
    setContentView(R.layout.activity_login);

    Button clickButton = (Button) findViewById(R.id.inst);
    final TypedValue typedValue = new TypedValue();
    clickButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            String mssg =
                "1. Login with facebook.\n"
                    + "2. This app will work only if other users are also on the same wifi network."
                    + "3. Select discover tab for seeing people around"
                    + "4. Select Match tab for seeing all your matches and chat with them by tapping on matches"
                    + "5. view your profile and preferences from action overflow"
                    + "6. logout by clicking logout button in action overflow";
            AlertDialog.Builder myAlert = new AlertDialog.Builder(LoginActivity.this);

            myAlert
                .setMessage(mssg)
                .setNeutralButton(
                    "Continue..",
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                      }
                    })
                .setTitle("!Instructions For You!")
                .setIcon(typedValue.resourceId)
                .create();
            myAlert.show();
          }
        });
    if (android.os.Build.VERSION.SDK_INT > 9) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }

    // System.setProperty("http.keepAlive", "false");

    // login button reference
    loginButton = (LoginButton) findViewById(R.id.login_button);

    // registering callback manager
    callbackManager = CallbackManager.Factory.create();
    loginButton.registerCallback(callbackManager, loginCallback());

    // setting permissions of login button
    loginButton.setReadPermissions(
        "user_photos", "user_about_me", "user_birthday", "user_location", "user_posts");

    WifiManager wifi_manager = (WifiManager) this.getSystemService(this.WIFI_SERVICE);
    if (!wifi_manager.isWifiEnabled()) {
      Toast.makeText(this, "enable your wifi", Toast.LENGTH_SHORT).show();
      AppServer.getInstance(this).killServer();
      NSDHelper.getInstance(this).tearDown();
      MessageClientHelper.getInstance(this).terminateMessageClient();
      // LoginManager.getInstance().logOut();
      finish();

    } else {

      // getting current access token
      accessToken = AccessToken.getCurrentAccessToken();

      //
      if (accessToken != null && accessToken.isExpired()) {
        LoginManager.getInstance()
            .logInWithReadPermissions(
                this,
                Arrays.asList(
                    "user_photos",
                    "user_about_me",
                    "user_birthday",
                    "user_location",
                    "user_posts"));
      } else if (accessToken != null && !accessToken.isExpired()) {
        // getPermanentToken();
        requestProfileInfo();
        // enterMainApp();
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mLM = LoginManager.getInstance();

    login = (LoginButton) findViewById(R.id.btn_login);
    callbackManager = CallbackManager.Factory.create();
    login.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {

          @Override
          public void onSuccess(LoginResult result) {
            AccessToken token = AccessToken.getCurrentAccessToken();
            Toast.makeText(
                    MainActivity.this, "login success : " + token.getUserId(), Toast.LENGTH_SHORT)
                .show();
          }

          @Override
          public void onError(FacebookException error) {
            Toast.makeText(MainActivity.this, "login error", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onCancel() {
            Toast.makeText(MainActivity.this, "login cancel", Toast.LENGTH_SHORT).show();
          }
        });

    btnLogin = (Button) findViewById(R.id.btn_login2);
    AccessToken token = AccessToken.getCurrentAccessToken();
    if (token == null) {
      btnLogin.setText("login");
    } else {
      btnLogin.setText("logout");
    }

    btnLogin.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            AccessToken token = AccessToken.getCurrentAccessToken();
            if (token == null) {
              mLM.logInWithReadPermissions(MainActivity.this, null);
            } else {
              mLM.logOut();
            }
          }
        });

    Button btn = (Button) findViewById(R.id.btn_post);
    btn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            AccessToken token = AccessToken.getCurrentAccessToken();
            if (token != null) {
              if (token.getPermissions().contains("publish_actions")) {
                sendPost();
                return;
              }
            }
            state = ActionState.POST;
            mLM.logInWithPublishPermissions(MainActivity.this, Arrays.asList("publish_actions"));
          }
        });

    btn = (Button) findViewById(R.id.btn_home);
    btn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            AccessToken token = AccessToken.getCurrentAccessToken();
            if (token != null) {
              if (token.getPermissions().contains("user_posts")) {
                readPost();
                return;
              }
            }
            state = ActionState.READ;
            mLM.logInWithReadPermissions(MainActivity.this, Arrays.asList("user_posts"));
          }
        });
    tracker =
        new AccessTokenTracker() {

          @Override
          protected void onCurrentAccessTokenChanged(
              AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (currentAccessToken != null) {
              btnLogin.setText("logout");
            } else {
              btnLogin.setText("login");
            }
          }
        };
  }