Пример #1
0
  private void setupViewObjects(User user) {
    ivCoverPic = (ImageView) mFragmentView.findViewById(R.id.ivCoverPic);
    ivProfilePic = (ImageView) mFragmentView.findViewById(R.id.ivProfilePic);
    TextView tvProfileName = (TextView) mFragmentView.findViewById(R.id.tvProfileName);
    TextView tvProfileLocation = (TextView) mFragmentView.findViewById(R.id.tvProfileLocation);

    Picasso.with(getContext())
        .load(
            "https://graph.facebook.com/"
                + user.getAuthId()
                + "/picture?width="
                + String.valueOf(getContext().getResources().getDisplayMetrics().widthPixels))
        .into(ivProfilePic /*new Target() {
                    @Override
                    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                        src = bitmap;
                        Resources res = getResources();
                        RoundedBitmapDrawable dr =
                                RoundedBitmapDrawableFactory.create(res, src);
                        dr.setCornerRadius(500f);
                        ivProfilePic.setImageDrawable(dr);
                    }

                    @Override
                    public void onBitmapFailed(Drawable errorDrawable) {

                    }

                    @Override
                    public void onPrepareLoad(Drawable placeHolderDrawable) {

                    }
                }*/);

    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {

              @Override
              public void onCompleted(JSONObject ret, GraphResponse graphResponse) {
                JSONObject cover = null;
                String url = null;
                try {
                  cover = ret.getJSONObject("cover");
                  url = cover.getString("source");
                } catch (JSONException e) {
                  e.printStackTrace();
                }
                Picasso.with(getContext()).load(url).into(ivCoverPic);
              }
            });

    Bundle parameters = new Bundle();
    parameters.putString("fields", "cover");
    request.setParameters(parameters);
    request.executeAsync();

    tvProfileName.setText(user.getName());
  }
 private void getUserDetails(AccessToken accessToken) {
   showProgress(getString(R.string.get_username_progress));
   GraphRequest graphRequest =
       GraphRequest.newMeRequest(
           accessToken,
           new GraphRequest.GraphJSONObjectCallback() {
             @Override
             public void onCompleted(JSONObject object, GraphResponse response) {
               dismissProgress();
               if (object != null) {
                 try {
                   final String username = object.getString("name");
                   Log.d("TarotFeedback", username);
                   Log.d("TarotFeedback", object.toString());
                   saveUsername(username);
                   addFeedback(username);
                 } catch (JSONException e) {
                   e.printStackTrace();
                 }
               } else {
                 Toast.makeText(
                         TarotFeedbackActivity.this,
                         getString(R.string.get_username_error),
                         Toast.LENGTH_SHORT)
                     .show();
               }
             }
           });
   Bundle parameters = new Bundle();
   parameters.putString("fields", "name");
   graphRequest.setParameters(parameters);
   graphRequest.executeAsync();
 }
Пример #3
0
  private void getMoreInformation(LoginResult loginResult) {
    GraphRequest request =
        GraphRequest.newMeRequest(
            loginResult.getAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject object, GraphResponse response) {

                Log.d(TAG, "response:" + response.toString());
                try {
                  String name = object.getString("name");
                  SharedPreferences.Editor editor = sp.edit();
                  editor.putString("fb_name", name);
                  editor.commit();
                  tv_name.setText(name);
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link,gender,birthday,email");
    request.setParameters(parameters);
    request.executeAsync();
  }
  public void requestFacebookUserDetails() {
    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject profile, GraphResponse response) {
                // JSONObject userProfile = new JSONObject();
                if (profile == null) {
                  Log.wtf("FIRST", "PROFILE VAZIO");
                } else {
                  ParseUser currentUser = ParseUser.getCurrentUser();
                  try {
                    currentUser.put("name", profile.get("name"));
                    currentUser.saveInBackground();
                    goToHomePage();
                  } catch (JSONException e) {
                    Log.wtf("ERROR DETAIL", "Erro ao pegar detalhes");
                  }
                }
              }
            });

    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,picture,name,link");
    request.setParameters(parameters);
    request.executeAsync();
  }
Пример #5
0
 private void getFacebookId() {
   AccessToken accessToken = AccessToken.getCurrentAccessToken();
   GraphRequest request =
       GraphRequest.newMeRequest(
           accessToken,
           new GraphRequest.GraphJSONObjectCallback() {
             @Override
             public void onCompleted(JSONObject object, GraphResponse response) {
               JSONObject result = response.getJSONObject();
               try {
                 String id = result.getString("id");
                 ParseUser user = ParseUser.getCurrentUser();
                 user.put("facebookId", id);
                 try {
                   user.save();
                 } catch (ParseException e) {
                   e.printStackTrace();
                 }
               } catch (JSONException e) {
                 e.printStackTrace();
               }
             }
           });
   Bundle parameters = new Bundle();
   parameters.putString("fields", "id");
   request.setParameters(parameters);
   request.executeAsync();
 }
  public void RequestData() {
    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject object, GraphResponse response) {

                JSONObject json = response.getJSONObject();
                try {
                  if (json != null) {
                    String text =
                        "<b>Name :</b> "
                            + json.getString("name")
                            + "<br><br><b>Email :</b> "
                            + json.getString("email")
                            + "<br><br><b>Profile link :</b> "
                            + json.getString("link");
                    details_txt.setText(Html.fromHtml(text));
                    profile.setProfileId(json.getString("id"));
                  }

                } catch (JSONException e) {
                  e.printStackTrace();
                }
              }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link,email,picture");
    request.setParameters(parameters);
    request.executeAsync();
  }
Пример #7
0
  private void getUserDetailsFromFB() {
    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                try {
                  userNameText = jsonObject.getString("name");
                } catch (JSONException e) {
                  e.printStackTrace();
                }
                try {
                  emailId = jsonObject.getString("email");
                } catch (JSONException e) {
                  e.printStackTrace();
                }

                saveNewUser();
              }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "name,email");
    request.setParameters(parameters);
    request.executeAsync();
  }
Пример #8
0
        @Override
        public void onSuccess(LoginResult loginResult) {

          GraphRequest request =
              GraphRequest.newMeRequest(
                  loginResult.getAccessToken(),
                  new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject object, GraphResponse response) {
                      final String email = object.optString("email");
                      final String id = object.optString("id");

                      final HashMap<String, String> params = new HashMap<>();
                      params.put("profileId", id);
                      params.put("email", email);

                      JsonObjectRequest request =
                          new JsonObjectRequest(
                              Request.Method.POST,
                              requestURL,
                              new JSONObject(params),
                              new Response.Listener<JSONObject>() {
                                @Override
                                public void onResponse(JSONObject response) {
                                  String userID = response.optJSONObject("data").optString("_id");

                                  SharedPreferences.Editor editor =
                                      getActivity()
                                          .getSharedPreferences(prefFile, Context.MODE_PRIVATE)
                                          .edit();
                                  editor.putString("facebookEmail", email);
                                  editor.putString("facebookId", id);
                                  editor.putString("userID", userID);
                                  editor.apply();

                                  getActivity().finish();
                                }
                              },
                              new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
                                  VolleyLog.d("Error", "Error: " + error.getMessage());
                                }
                              });
                      VolleyApplication.getInstance().getRequestQueue().add(request);
                    }
                  });
          Bundle parameters = new Bundle();
          parameters.putString("fields", "email");
          request.setParameters(parameters);
          request.executeAsync();
        }
Пример #9
0
  private void makeMeRequest() {
    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject user, GraphResponse response) {
                if (user != null) {

                  JSONObject userProfile = new JSONObject();
                  try {

                    // profilePicture.setProfileId(user.getString("id"));

                    userProfile.put("facebookId", user.getLong("id"));
                    userProfile.put("name", user.getString("name"));
                    if (user.getString("gender") != null) {
                      userProfile.put("gender", (String) user.getString("gender"));
                    }
                    if (user.getString("email") != null) {
                      userProfile.put("email", (String) user.getString("email"));
                    }

                    ParseUser currentUser = ParseUser.getCurrentUser();
                    currentUser.put("name", user.getString("name"));
                    currentUser.put("type", "User");
                    currentUser.put("profile", userProfile);

                  } catch (JSONException e) {
                    Log.d("My", "Error parsing returned user data. " + e);
                  }

                } else if (response.getError() != null) {
                  switch (response.getError().getCategory()) {
                    case LOGIN_RECOVERABLE:
                      Log.d("theSOS", "Authentication error: " + response.getError());
                      break;

                    case TRANSIENT:
                      Log.d("theSOS", "Transient error. Try again. " + response.getError());
                      break;

                    case OTHER:
                      Log.d("theSOS", "Some other error: " + response.getError());
                      break;
                  }
                }
              }
            });
    request.executeAsync();
  }
Пример #10
0
  @Override
  public void onSuccess(final LoginResult loginResult) {
    if (loginResult == null || loginResult.getAccessToken() == null) {
      return;
    }

    Logger.debug(LoginActivity.TAG, loginResult.getAccessToken().getApplicationId());
    Logger.debug(LoginActivity.TAG, loginResult.getAccessToken().getToken());
    Logger.debug(LoginActivity.TAG, loginResult.getAccessToken().getUserId());

    // Request me
    final GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), this);
    request.setParameters(LoginActivity.FACEBOOK_ME_PERMISSION);
    request.executeAsync();
  }
Пример #11
0
 private void getUserFacebookDetails(LoginResult loginResult) {
   final AccessToken token = loginResult.getAccessToken();
   GraphRequest request =
       GraphRequest.newMeRequest(
           loginResult.getAccessToken(),
           new GraphRequest.GraphJSONObjectCallback() {
             @Override
             public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
               Log.v("LoginActivity", graphResponse.toString());
               sharedPreferences.edit().putString("latestFbLogin", jsonObject.toString());
               parseFBData(jsonObject, token);
             }
           });
   Bundle parameters = new Bundle();
   parameters.putString("fields", "id,email,gender, birthday,first_name,last_name");
   request.setParameters(parameters);
   request.executeAsync();
 }
  private void getUserInfo() {
    Bundle parameters = new Bundle();
    final AlertDialog alertDialog =
        new AlertDialog.Builder(activityWeakReference.get())
            .setMessage("Baixando informações do usuário...")
            .setCancelable(false)
            .show();

    GraphRequest graphRequest =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                alertDialog.dismiss();
                changeCurrentState(StatusFacebookConn.CONNECTED);
                Log.i(TAGINFO, "Getting user info completed/Connected");
                try {
                  activityWeakReference
                      .get()
                      .getSharedPreferences("FacebookSession", Context.MODE_PRIVATE)
                      .edit()
                      .putString("FacebookEmail", jsonObject.getString("email"))
                      .commit();
                  activityWeakReference
                      .get()
                      .getSharedPreferences("FacebookSession", Context.MODE_PRIVATE)
                      .edit()
                      .putBoolean("FacebookLogged", true)
                      .commit();
                } catch (JSONException e) {
                  Log.e(TAGERROR, e.getMessage() + " - " + e.getCause());
                }
              }
            });
    parameters.putString("fields", "email");
    graphRequest.setParameters(parameters);
    graphRequest.executeAsync();
    Log.i(TAGINFO, "Requesting user info");
  }
 protected void checkFacebookSession() {
   AccessToken accessToken = AccessToken.getCurrentAccessToken();
   if (accessToken != null && !accessToken.isExpired()) {
     GraphRequest request =
         GraphRequest.newMeRequest(
             accessToken,
             new GraphRequest.GraphJSONObjectCallback() {
               @Override
               public void onCompleted(JSONObject userJson, GraphResponse graphResponse) {
                 User.facebookUser(userJson);
               }
             });
     Bundle parameters = new Bundle();
     parameters.putString("fields", "id,name,link,gender,birthday,email");
     request.setParameters(parameters);
     request.executeAsync();
   } else {
     List<String> permissions = new ArrayList<String>();
     permissions.add("public_profile");
     permissions.add("email");
     LoginManager.getInstance().logInWithReadPermissions(getActivity(), permissions);
   }
 }
Пример #14
0
        @Override
        public void onSuccess(LoginResult loginResult) {

          GraphRequest request =
              GraphRequest.newMeRequest(
                  loginResult.getAccessToken(),
                  new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                      try {
                        FBmap = new LinkedMultiValueMap<String, String>();
                        FBmap.add("nome", jsonObject.getString("name"));
                        FBmap.add("email", jsonObject.getString("email"));
                        FBmap.add("senha", jsonObject.getString("id"));
                        urlFoto =
                            jsonObject
                                .getJSONObject("picture")
                                .getJSONObject("data")
                                .getString("url");

                        new HttpBuscaEmailFB(
                                (new Webservice()).buscaUsuarioEmail(jsonObject.getString("email")),
                                null,
                                Usuario.class,
                                "")
                            .execute();

                      } catch (JSONException e) {
                        e.printStackTrace();
                      }
                    }
                  });
          Bundle params = new Bundle();
          params.putString("fields", "id,name,email,picture");
          request.setParameters(params);
          request.executeAsync();
        }
  private void requestProfileInfo() {
    String request_string = "/" + AccessToken.getCurrentAccessToken().getUserId() + "/picture";
    Bundle parameters = new Bundle();
    parameters.putBoolean("redirect", false);
    parameters.putInt("height", 300);
    parameters.putInt("width", 300);

    GraphRequest dp_request =
        new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            request_string,
            parameters,
            HttpMethod.GET,
            new GraphRequest.Callback() {

              @Override
              public void onCompleted(GraphResponse graphResponse) {
                JSONObject obj = graphResponse.getJSONObject();
                try {
                  JSONObject profile_data = (JSONObject) obj.get("data");
                  String current_dp_url = (String) profile_data.get("url");
                  url = current_dp_url;

                } catch (JSONException e) {
                  Log.d(TAG, "something went wrong with profile picture request");
                } catch (NullPointerException e) {
                  e.printStackTrace();
                  Log.d(TAG, graphResponse.getError().toString());
                }
              }
            });

    // dp_request.setParameters(parameters);

    // request for name, gender, age_range
    GraphRequest meRequest =
        GraphRequest.newMeRequest(
            accessToken,
            new GraphRequest.GraphJSONObjectCallback() {

              @Override
              public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                try {
                  name = jsonObject.getString("first_name");
                  String gender_string = jsonObject.getString("gender");
                  if (gender_string.equals("male")) {
                    gender = false;
                  } else {
                    gender = true;
                  }
                  age = 21;

                } catch (JSONException e) {
                  e.printStackTrace();
                } catch (NullPointerException e) {
                  e.printStackTrace();
                }
              }
            });

    // saveUserToDB();

    parameters = new Bundle();
    parameters.putString("fields", "id,first_name, gender, age_range");

    meRequest.setParameters(parameters);

    final GraphRequestBatch request;
    request = new GraphRequestBatch(meRequest, dp_request);
    meRequest.executeAndWait();
    dp_request.executeAndWait();
    saveUserToDB();
    registerUser();
  }
Пример #16
0
  public void getFacebookData() {
    final ArrayList<String> strings = new ArrayList<>();
    GraphRequestBatch batch;
    batch =
        new GraphRequestBatch(
            GraphRequest.newMeRequest(
                access_token,
                new GraphRequest.GraphJSONObjectCallback() {
                  @Override
                  public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                    if (graphResponse.getError() != null) {
                      // handle error
                      System.out.println("ERROR");
                    } else {
                      System.out.println("Success");
                    }

                    try {
                      String jsonresult = String.valueOf(jsonObject);
                      System.out.println("JSON Result" + jsonresult);
                      String str_firstname = jsonObject.getString("name");
                      nameText.setText(str_firstname);
                    } catch (JSONException e) {
                      e.printStackTrace();
                    }
                  }
                }),
            new GraphRequest(
                access_token,
                "me/feed",
                null,
                HttpMethod.GET,
                new GraphRequest.Callback() {
                  @Override
                  public void onCompleted(GraphResponse graphResponse) {
                    if (graphResponse.getError() != null) {
                      // handle error
                      System.out.println("ERROR");
                    } else {
                      System.out.println("Success");
                    }

                    try {
                      JSONObject json = null;
                      JSONArray jarray = null;
                      json = new JSONObject(graphResponse.getRawResponse());
                      jarray = json.getJSONArray("data");
                      for (int i = 0; i < jarray.length(); i++) {
                        JSONObject oneStory = null;
                        oneStory = jarray.getJSONObject(i);

                        String story;

                        story = oneStory.optString("story");
                        if (story.isEmpty()) story = oneStory.optString("message");
                        strings.add(i, story);
                      }
                    } catch (JSONException e) {
                      e.printStackTrace();
                    }

                    Log.d("RESPONSE", strings.toString());
                    ArrayAdapter<String> arrayAdapter =
                        new ArrayAdapter<String>(
                            MainActivity.this, android.R.layout.simple_list_item_1, strings);
                    dataList.setAdapter(arrayAdapter);
                  }
                }));

    batch.executeAsync();
  }
Пример #17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    mCallbackManager = CallbackManager.Factory.create();

    getSupportActionBar().hide();

    if (mata_sessao) {
      LoginManager.getInstance().logOut();
    }

    final EditText etEmail = (EditText) findViewById(R.id.etEmail);
    final EditText etSenha = (EditText) findViewById(R.id.etSenha);
    etEmail.requestFocus();

    Button btEntrar = (Button) findViewById(R.id.btEntrar);

    btEntrar.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
            map.add("email", String.valueOf(etEmail.getText().toString()));
            map.add("senha", String.valueOf(etSenha.getText().toString()));

            Usuario usuario = new Usuario();
            Webservice ws = new Webservice();
            new HttpLogin(ws.login(), map, Usuario.class, "").execute();
          }
        });

    TextView tvCadastrar = (TextView) findViewById(R.id.tvCadastrar);

    tvCadastrar.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            Intent tela1 = new Intent(Login.this, Cadastro.class);
            startActivity(tela1);
          }
        });

    ProfileTracker profileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile profile, Profile newProfile) {}
        };

    LoginButton FBLoginButton = (LoginButton) findViewById(R.id.fb_login_button);
    FBLoginButton.registerCallback(mCallbackManager, mCallBack);

    if (AccessToken.getCurrentAccessToken() != null) {
      GraphRequest request2 =
          GraphRequest.newMeRequest(
              AccessToken.getCurrentAccessToken(),
              new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                  try {
                    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
                    map.add("email", jsonObject.getString("email"));
                    map.add("senha", jsonObject.getString("id"));

                    new HttpLoginFB((new Webservice()).login(), map, Usuario.class, "").execute();

                  } catch (JSONException e) {
                    e.printStackTrace();
                  }
                }
              });
      Bundle params2 = new Bundle();
      params2.putString("fields", "id,name,email");
      request2.setParameters(params2);
      request2.executeAsync();
    }
  }