/** Get the current user profile info */
  private void makeMeRequest() {
    final Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
      Request request =
          Request.newMeRequest(
              session,
              new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user, Response response) {
                  isMakeMeRequestStarted = false;
                  dismissProgressDialog();

                  if (session == Session.getActiveSession() && user != null) {
                    mUser = user;
                    updateUI();
                  }
                  if (response != null && response.getError() != null) {
                    Utils.handleError(
                        getActivity(), response.getError(), Utils.getProfileReadPermission());
                  }
                }
              });
      request.executeAsync();
    }
  }
Beispiel #2
0
 private void makeMeRequest(final Session session) {
   // Make an API call to get user data and define a
   // new callback to handle the response.
   Request request =
       Request.newMeRequest(
           session,
           new Request.GraphUserCallback() {
             @Override
             public void onCompleted(GraphUser user, Response response) {
               // If the response is successful
               if (session == Session.getActiveSession()) {
                 if (user != null) {
                   /*Geocoder gcd = new Geocoder(getApplicationContext(), Locale.getDefault());
                   List<Address> addresses = gcd.getFromLocation(lat, lng, 1);
                   if (addresses.size() > 0)
                       System.out.println(addresses.get(0).getLocality());*/
                   if (!registered)
                     RegisterUser(user.getId(), user.getName(), user_location, user.getUsername());
                   else initiateLoading();
                   fb_user = user;
                   // LoadData();
                 }
               }
               if (response.getError() != null) {
                 // Handle errors, will do so later.
               }
             }
           });
   request.executeAsync();
 }
Beispiel #3
0
 /**
  * Will make a request to the facebook API and return with the some information about the user. It
  * will then set some layout text fields with the user image and username. It will also make a
  * request to the server for saving the username into the server's database.
  *
  * @param session is the current state or session for the user
  */
 private void makeMeRequest(final Session session) {
   // Make an API call to get user data and define a
   // new callback to handle the response.
   Request request =
       Request.newMeRequest(
           session,
           new Request.GraphUserCallback() {
             @Override
             public void onCompleted(GraphUser user, Response response) {
               // If the response is successful
               if (session == Session.getActiveSession()) {
                 if (user != null) {
                   // Set the id for the ProfilePictureView
                   // view that in turn displays the profile
                   // picture.
                   profilePictureView.setProfileId(user.getId());
                 }
               }
               if (response.getError() != null) {
                 // Handle errors, will do so later.
               }
             }
           });
   request.executeAsync();
 }
  private void makeMeRequest(final Session session) {

    // Make an API call to get user data and define a
    // new callback to handle the response.
    Request request =
        Request.newMeRequest(
            session,
            new Request.GraphUserCallback() {
              @Override
              public void onCompleted(GraphUser user, Response response) {
                // If the response is successful
                if (session == Session.getActiveSession()) {
                  if (user != null) {
                    ((OmniDriveApplication) getActivity().getApplication()).setCurrentFBUser(user);
                    // Set the id for the ProfilePictureView
                    // view that in turn displays the profile picture.
                    profilePictureView.setProfileId(user.getId());
                    // Set the Textview's text to the user's name.
                    userNameView.setText(user.getName());
                  }
                }
                if (response.getError() != null) {
                  // Handle errors, will do so later.
                }
              }
            });
    request.executeAsync();

    getAllFriends(session);
  }
Beispiel #5
0
  private void Poimg(Bitmap b) {

    Session session = Session.getActiveSession();
    if (session != null) {

      // Part 1: create callback to get URL of uploaded photo
      Request.Callback uploadPhotoRequestCallback =
          new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
              // safety check
              if (isFinishing()) {
                return;
              }
              if (response.getError() != null) { // [IF Failed Posting]
                Log.d("", "photo upload problem. Error=" + response.getError());
                System.out.println(response.getError());
              } //  [ENDIF Failed Posting]
              Object graphResponse = response.getGraphObject().getProperty("id");
              if (graphResponse == null
                  || !(graphResponse instanceof String)
                  || TextUtils.isEmpty((String) graphResponse)) { // [IF Failed upload/no results]
                Log.d("", "failed photo upload/no response");
              } else { // [ELSEIF successful upload]
                fbPhotoAddress = "https://www.facebook.com/photo.php?fbid=" + graphResponse;

                System.out.println(fbPhotoAddress + "/////");
              } // [ENDIF successful posting or not]
            } // [END onCompleted]
          };

      // Part 2: upload the photo
      Request request = Request.newUploadPhotoRequest(session, b, uploadPhotoRequestCallback);
      Bundle bundle = request.getParameters();
      bundle.putString(
          "message",
          "受測者:"
              + UserName
              + "\n拍攝日期:"
              + Data[0]
              + "\n酒測值:"
              + Data[1]
              + "/L"
              + "\n位置:"
              + returnAddress);
      request.setParameters(bundle);
      /*紫陽科技酒測即時群組*/
      request.setGraphPath("615097428532040/photos");
      /*
       * 	測試群組
       * request.setGraphPath("612077312161579/photos");
       */
      /*	個人塗鴉牆
       * request.setGraphPath("me/photos");
       */
      request.executeAsync();
    }
  }
        @Override
        public void call(Session session, SessionState state, Exception exception) {

          if (state.isOpened()) {

            if (getCount() > 0) return;

            Request friendRequest =
                Request.newMyFriendsRequest(
                    Session.getActiveSession(),
                    new GraphUserListCallback() {
                      @Override
                      public void onCompleted(List<GraphUser> users, Response response) {

                        if (getCount() > 0) return;

                        if (users != null) {

                          for (GraphUser graphUser : users) {

                            ContentValues values = new ContentValues();
                            JSONObject userJson = graphUser.getInnerJSONObject();
                            if (userJson != null) {

                              JSONObject pictureJson = userJson.optJSONObject("picture");
                              if (pictureJson != null) {

                                JSONObject dataPictureJson = pictureJson.optJSONObject("data");
                                if (dataPictureJson != null)
                                  values.put(
                                      DBHelper.KEY_COLUMN_PICTURE,
                                      dataPictureJson.optString("url"));
                              }
                            }
                            values.put(DBHelper.KEY_COLUMN_ID, graphUser.getId());
                            values.put(
                                DBHelper.KEY_COLUMN_NAME,
                                graphUser.getFirstName() + " " + graphUser.getLastName());
                            getActivity()
                                .getContentResolver()
                                .insert(DBProvider.CONTENT_DATA_URI, values);
                          }
                        }
                      }
                    });
            Bundle params = new Bundle();
            params.putString("fields", "id, first_name, last_name, picture.type(large)");
            friendRequest.setParameters(params);
            friendRequest.executeAsync();
          } else if (state.isClosed()) {

          }
        }
 @Override
 public void handleMessage(Message msg) {
   switch (msg.what) {
     case EXECUTE_REQUEST:
       {
         Request request = (Request) msg.obj;
         request.executeAsync();
         break;
       }
     case EXECUTE_WEBDIALOG:
       {
         mFacebookPlugin._ui((String) (msg.obj), msg.arg1);
         break;
       }
     default:
       break;
   }
 }
  private void getFacebookInfos() {
    showLoadingDialog(LOADING_NO_MSG, LOADING_NO_MSG, false);
    Request.executeMeRequestAsync(
        Session.getActiveSession(),
        new GraphUserCallback() {

          @Override
          public void onCompleted(GraphUser user, Response response) {
            // TODO Auto-generated method stub\
            if (user == null) {
              facebookRequestError();
              return;
            }
            hasUserInfoLoaed = true;
            mUser = user;
            if (hasFriendsLoaded) {
              onFacebookInfoLoaded(mUser, mFriends);
            }
          }
        });
    Request request =
        Request.newMyFriendsRequest(
            Session.getActiveSession(),
            new GraphUserListCallback() {

              @Override
              public void onCompleted(List<GraphUser> users, Response response) {
                // TODO Auto-generated method
                if (users == null) {
                  facebookRequestError();
                  return;
                }
                mFriends = FacebookUtil.buildFriends(users);
                hasFriendsLoaded = true;
                if (hasUserInfoLoaed) {
                  onFacebookInfoLoaded(mUser, mFriends);
                }
              }
            });
    request.executeAsync();
  }
  private void getAllFriends(final Session session) {
    Request friendsRequest =
        Request.newMyFriendsRequest(
            session,
            new Request.GraphUserListCallback() {

              @Override
              public void onCompleted(List<GraphUser> users, Response response) {
                FacebookRequestError error = response.getError();
                if (error != null) {
                  Log.e(OmniDriveApplication.TAG, error.toString());
                } else if (session == Session.getActiveSession()) {
                  // Set the friends attribute
                  ((OmniDriveApplication) getActivity().getApplication()).setFriends(users);
                }
              }
            });
    Bundle params = new Bundle();
    params.putString("fields", "name,first_name,last_name");
    friendsRequest.setParameters(params);
    friendsRequest.executeAsync();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_rest, container, false);
    Intent data = getActivity().getIntent();
    eid = data.getStringExtra("eid");
    event_name = data.getStringExtra("name");
    et_name = (EditText) view.findViewById(R.id.et_name);
    btnChat = (Button) view.findViewById(R.id.buttonChat);
    btnChat.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (btnChat.getText().equals("Chat!")) {
              Intent intent = new Intent(getActivity().getApplicationContext(), ChatActivity.class);
              name = et_name.getText().toString();
              if (name.trim().length() > 0) {
                intent.putExtra("name", name);
                intent.putExtra("event_name", event_name);
                intent.putExtra("eid", eid);
                startActivity(intent);
              } else {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder
                    .setTitle("Error")
                    .setMessage("Please fill in your name.")
                    .setCancelable(false)
                    .setNegativeButton(
                        "Ok",
                        new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                          }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
              }
            }
          }
        });

    String fqlQuery = "SELECT name FROM user where uid = me()";
    Bundle params = new Bundle();
    params.putString("q", fqlQuery);
    NetworkTracker ntrack = new NetworkTracker(getActivity());
    if (ntrack.getNetwork()) {
      Session session = Session.getActiveSession();
      params.putString("t", session.getAccessToken());
      Request request =
          new Request(session, "/fql?q=QUERY&access_token=t", params, HttpMethod.GET, callback);
      request.executeAsync();

    } else {
      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
      alertDialogBuilder
          .setTitle("Error")
          .setMessage("No internet connection available.")
          .setCancelable(false)
          .setNegativeButton(
              "Ok",
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                  dialog.cancel();
                }
              });
      AlertDialog alertDialog = alertDialogBuilder.create();
      alertDialog.show();
    }

    return view;
  }
Beispiel #11
0
  private void makeMeRequest(final Session session) {
    // Make an API call to get user data and define a
    // new callback to handle the response.
    Request request =
        Request.newMeRequest(
            session,
            new Request.GraphUserCallback() {
              public void onCompleted(GraphUser user, Response response) {
                // If the response is successful
                if (session == Session.getActiveSession()) {
                  if (user != null) {
                    fb_uid = user.getId();

                    first_name = user.getFirstName();
                    last_name = user.getLastName();

                    if (user.getBirthday() != null) {
                      birthdate = formatDate(user.getBirthday());
                      // Log.i ("facebook info birthday: ", birthdate);
                    }

                    gender = "M";
                    if (user.getProperty("gender").toString().contentEquals("male")) {
                      gender = "M";
                    } else if (user.getProperty("gender").toString().contentEquals("female")) {
                      gender = "F";
                    }
                    // Log.i ("facebook info gender: ", gender);

                    /*
                    email_is_verified = 1;
                    if ((Boolean) user.getProperty("verified")){
                    	email_is_verified = 1;
                    } else {
                    	email_is_verified = 0;
                    }
                    */
                    // Log.i ("facebook info verified: ", String.valueOf(email_is_verified));

                    mHandler.post(
                        new Runnable() {
                          public void run() {
                            RestClient result = null;
                            try {
                              result =
                                  new Rest.requestBody()
                                      .execute(
                                          Rest.USER,
                                          Rest.OTOKE + Rest.accessCode2,
                                          Rest.POST,
                                          "7",
                                          "email",
                                          email,
                                          "firstname",
                                          first_name,
                                          "lastname",
                                          last_name,
                                          "date_of_birth",
                                          birthdate,
                                          "gender",
                                          gender,
                                          "school_id",
                                          String.valueOf(schoolid),
                                          "facebook_uid",
                                          fb_uid)
                                      .get();
                            } catch (InterruptedException e1) {
                              // TODO Auto-generated catch block
                              e1.printStackTrace();
                            } catch (ExecutionException e1) {
                              // TODO Auto-generated catch block
                              e1.printStackTrace();
                            }
                            Log.i("create account facebook result", result.getResponse());

                            if (result.getResponseCode() == 201) {
                              setUserPW(fb_uid);
                              showAlertDialog();
                            } else if (result.getResponseCode() == 403
                                && result.getResponse().contains("age")) {
                              onClickLogout();
                              showErrorAlertDialog(
                                  getString(
                                      R.string
                                          .Registration_failed_The_user_does_not_satisfy_the_age_requirements_of_the_app));
                            } else if (result.getResponseCode() == 409
                                && result.getResponse().contains("email")) {
                              onClickLogout();
                              showErrorAlertDialog(
                                  getString(
                                      R.string
                                          .Registration_failed_The_email_has_been_used_in_another_account));
                            } else if (result.getResponseCode() == 409
                                && result.getResponse().contains("facebook_uid")) {
                              onClickLogout();
                              showErrorAlertDialog(
                                  getString(
                                      R.string
                                          .Registration_failed_Facebook_account_already_has_an_account_on_OOHLALA));
                            }
                          }
                        });
                  }
                }
                if (response.getError() != null) {
                  // Handle errors, will do so later.
                  Log.i("facebook response errorMessage: ", response.getError().getErrorMessage());
                  makeMeRequest(session);
                }
              }
            });
    request.executeAsync();
  }