/** * Creates a new Request configured to upload an image to create a staging resource. Staging * resources allow you to post binary data such as images, in preparation for a post of an Open * Graph object or action which references the image. The URI returned when uploading a staging * resource may be passed as the image property for an Open Graph object or action. * * @param accessToken the access token to use, or null * @param file the file containing the image to upload * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws FileNotFoundException */ public static GraphRequest newUploadStagingResourceWithImageRequest( AccessToken accessToken, File file, Callback callback ) throws FileNotFoundException { ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); GraphRequest.ParcelableResourceWithMimeType<ParcelFileDescriptor> resourceWithMimeType = new GraphRequest.ParcelableResourceWithMimeType<>(descriptor, "image/png"); Bundle parameters = new Bundle(1); parameters.putParcelable(STAGING_PARAM, resourceWithMimeType); return new GraphRequest( accessToken, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback); }
private void shareLinkContent(final ShareLinkContent linkContent, final FacebookCallback<Sharer.Result> callback) { final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { final JSONObject data = response.getJSONObject(); final String postId = (data == null ? null : data.optString("id")); ShareInternalUtility.invokeCallbackWithResults(callback, postId, response); } }; final Bundle parameters = new Bundle(); this.addCommonParameters(parameters, linkContent); parameters.putString("message", this.getMessage()); parameters.putString("link", Utility.getUriString(linkContent.getContentUrl())); parameters.putString("picture", Utility.getUriString(linkContent.getImageUrl())); parameters.putString("name", linkContent.getContentTitle()); parameters.putString("description", linkContent.getContentDescription()); parameters.putString("ref", linkContent.getRef()); new GraphRequest( AccessToken.getCurrentAccessToken(), getGraphPath("feed"), parameters, HttpMethod.POST, requestCallback).executeAsync(); }
public static void getGraphMeRequestWithCacheAsync( final String accessToken, final GraphMeRequestWithCacheCallback callback) { JSONObject cachedValue = ProfileInformationCache.getProfileInformation(accessToken); if (cachedValue != null) { callback.onSuccess(cachedValue); return; } GraphRequest.Callback graphCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { if (response.getError() != null) { callback.onFailure(response.getError().getException()); } else { ProfileInformationCache.putProfileInformation( accessToken, response.getJSONObject()); callback.onSuccess(response.getJSONObject()); } } }; GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken); graphRequest.setCallback(graphCallback); graphRequest.executeAsync(); }
@Override protected void subscribeActual(@NonNull SingleObserver<? super GraphResponse> observer) { mObserver = observer; GraphRequest request = GraphRequest.newMeRequest(mAccessToken, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { if (response.getError() == null) { mObserver.onSuccess(response); } else { mObserver.onError(response.getError().getException()); } } }); Bundle parameters = new Bundle(); parameters.putString("fields", mFields); request.setParameters(parameters); request.executeAsync(); }
public void getPermissions() { String uri = "me/permissions/"; new GraphRequest(AccessToken.getCurrentAccessToken(), uri, null, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { /* handle the result */ JSONArray data = response.getJSONObject().optJSONArray("data"); mUserPermissions.clear(); for (int i = 0; i < data.length(); i++) { JSONObject dd = data.optJSONObject(i); if (dd.optString("status").equals("granted")) { mUserPermissions .add(dd.optString("permission")); } } } } ).executeAsync(); }
public void revokePermission(final String permission) { AccessToken token = AccessToken.getCurrentAccessToken(); String uri = "me/permissions/" + permission; GraphRequest graphRequest = GraphRequest.newDeleteObjectRequest( token, uri, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { FacebookRequestError error = response.getError(); if (error == null) { Utils.d("FB:Revoke:Response:" + response.toString()); getPermissions(); } } }); graphRequest.executeAsync(); }
/** GraphRequest **/ public void revokeAccess() { mAuth.signOut(); AccessToken token = AccessToken.getCurrentAccessToken(); GraphRequest graphRequest = GraphRequest.newDeleteObjectRequest( token, "me/permissions", new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { FacebookRequestError error = response.getError(); if (error == null) { Utils.d("FB:Delete:Access" + response.toString()); } } }); graphRequest.executeAsync(); }
public void loadRequests() { AccessToken token = AccessToken.getCurrentAccessToken(); GraphRequest myRequests = GraphRequest.newGraphPathRequest( token, "/me/apprequests", new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { FacebookRequestError error = response.getError(); if (error == null) { JSONObject graphObject = response.getJSONObject(); JSONArray data = graphObject.optJSONArray("data"); Utils.callScriptFunc("pendingRequest", data.toString()); } else { Utils.d("Response Error: " + error.toString()); } } }); myRequests.executeAsync(); }
public static void deleteRequest (String requestId) { // delete Requets here GraphAPI. Utils.d("Deleting:Request:" + requestId); AccessToken token = AccessToken.getCurrentAccessToken(); GraphRequest graphRequest = GraphRequest.newDeleteObjectRequest( token, requestId, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { FacebookRequestError error = response.getError(); if (error == null) { Utils.d("OnDelete:Req:" + response.toString()); } } }); graphRequest.executeAsync(); }
public static void getUserDataFromRequest (String requestId) { // Grah Api to get user data from request. AccessToken token = AccessToken.getCurrentAccessToken(); GraphRequest graphRequest = GraphRequest.newGraphPathRequest( token, requestId, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { FacebookRequestError error = response.getError(); if (error == null) { Utils.d("Response: " + response.toString()); } else { Utils.d("Error: " + response.toString()); } } }); graphRequest.executeAsync(); }
@Override public void onSuccess(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { String socialId = null, name = null; try { socialId = object.getString("id"); name = object.getString("name"); }catch (Exception e){} register(socialId, name); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name"); request.setParameters(parameters); request.executeAsync(); }
private void queryMe(Result result) { GraphRequest request = GraphRequest.newMeRequest( AccessToken.getCurrentAccessToken(), (object, response) -> { try { result.success(JsonConverter.convertToMap(object)); } catch (JSONException e) { result.error(TAG, "Error", e.getMessage()); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email"); request.setParameters(parameters); request.executeAsync(); }
private void facebookLogin(LoginResult loginResult){ GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback(){ @Override public void onCompleted(JSONObject object, GraphResponse response){ JSONObject jsonObject = response.getJSONObject(); UserAccountControl userAccountControl = UserAccountControl .getInstance(getApplicationContext()); userAccountControl.authenticateLoginFb(object); userAccountControl.logInUserFromFacebook(jsonObject); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email,gender"); request.setParameters(parameters); request.executeAsync(); }
private void facebookLogin(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { UserAccountControl userAccountControl = UserAccountControl .getInstance(getApplicationContext()); userAccountControl.authenticateLoginFb(object); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email,gender"); request.setParameters(parameters); request.executeAsync(); }
private void createAppLinkIfNeeded() { if (mPlace != null && mAppLink == null && Utils.isConnected(getContext())) { String token = getContext().getString(R.string.facebook_app_id) + "|" + getContext().getString(R.string.facebook_app_secret); Bundle parameters = new Bundle(); parameters.putString("name", "Sjekk Ut"); parameters.putString("access_token", token); parameters.putString("web", "{\"should_fallback\": false}"); parameters.putString("iphone", "[{\"url\": \"sjekkut://place/" + mPlace.getId() + "\"}]"); parameters.putString("android", "[{\"url\": \"no.dnt.sjekkut://place/" + mPlace.getId() + "\", \"package\": \"no.dnt.sjekkut\"}]"); new GraphRequest( null, "/app/app_link_hosts", parameters, HttpMethod.POST, this).executeAsync(); } }
@Override public void onSuccess(LoginResult loginResult) { final String fbAccessToken = loginResult.getAccessToken().getToken(); PreferenceManager.getDefaultSharedPreferences(context).edit().putString(TOKEN_FB_KEY,fbAccessToken); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email"); GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { if (onFacebookEvent != null) { InfoSocial infoSocial = new InfoSocial(); infoSocial.setAccessToken(fbAccessToken); infoSocial.setName(object.optString("name")); infoSocial.setEmail(object.optString("email")); infoSocial.setUserId(object.optString("id")); onFacebookEvent.onFacebookSuccess(infoSocial); } } }); request.setParameters(parameters); request.executeAsync(); }
private Single<String> getFacebookEmail(AccessToken accessToken) { return Single.defer(() -> { try { final GraphResponse response = GraphRequest.newMeRequest(accessToken, null) .executeAndWait(); final JSONObject object = response.getJSONObject(); if (response.getError() == null && object != null) { try { return Single.just( object.has("email") ? object.getString("email") : object.getString("id")); } catch (JSONException ignored) { return Single.error( new FacebookSignUpException(FacebookSignUpException.ERROR, "Error parsing email")); } } else { return Single.error(new FacebookSignUpException(FacebookSignUpException.ERROR, "Unknown error(maybe network error when getting user data)")); } } catch (RuntimeException exception) { return Single.error( new FacebookSignUpException(FacebookSignUpException.ERROR, exception.getMessage())); } }) .subscribeOn(Schedulers.io()); }
/** * Requests user graph data * Use permission parameters e.g. "id, first_name, last_name, email, gender" * * @param accessToken * @param permissionParams * @param onFacebookGraphResponse */ public void requestGraphData(final AccessToken accessToken, String permissionParams, final OnFacebookGraphResponse onFacebookGraphResponse) { GraphRequest request = GraphRequest.newMeRequest(accessToken, (object, response) -> { if (object == null) { Log.d(TAG, "Response is null"); return; } Log.d(TAG, "Object received: " + object.toString()); onFacebookGraphResponse.onCompleted(object, response); } ); Bundle parameters = new Bundle(); parameters.putString("fields", permissionParams); request.setParameters(parameters); request.executeAsync(); }
@Override public List<String> getThirdPartyFriendIds() throws SocialNetworkException { if (!isAuthorizedToSocialNetwork()) { throw new NotAuthorizedToSocialNetworkException(); } GraphResponse response = new GraphRequest( facebookTokenHolder.getToken(), FACEBOOK_FRIENDS_GRAPH_PATH, Bundle.EMPTY, HttpMethod.GET ).executeAndWait(); facebookTokenHolder.clearToken(); FacebookRequestError responseError = response.getError(); if (responseError != null) { throw new SocialNetworkException("Internal facebook failure: " + responseError.getErrorMessage() + " [" + responseError.getErrorCode() + "]"); } return extractFacebookFriendIds(response); }
public void setPhoto(final ImageView imageView, final Button button){ new GraphRequest( AccessToken.getCurrentAccessToken(), "me?fields=picture.width(500).height(500)", null, HttpMethod.GET, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { try { Log.d("LOG onComplete", String.valueOf(AccessToken.getCurrentAccessToken())); String url=new FacebookJsonParse().FacebookImageParse(response.getJSONObject()); imageView.setVisibility(View.VISIBLE); button.setVisibility(View.GONE); Glide.with(context).load(url).into(imageView); } catch (JSONException e) { Log.d("FacebookSdkHelper",e.getMessage()); } } } ).executeAsync(); }
protected void execute() { if (sessionManager.isLoggedIn()) { AccessToken accessToken = sessionManager.getAccessToken(); Bundle bundle = updateAppSecretProof(); GraphRequest request = new GraphRequest(accessToken, getGraphPath(), bundle, HttpMethod.GET); request.setVersion(configuration.getGraphVersion()); runRequest(request); } else { String reason = Errors.getError(Errors.ErrorMsg.LOGIN); Logger.logError(getClass(), reason, null); if (mSingleEmitter != null) { mSingleEmitter.onError(new FacebookAuthorizationException(reason)); } } }
private void getUserEmail(AccessToken accessToken) { GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { try { updateUserData(object.getString("email")); } catch (JSONException e) { updateUserData(""); e.printStackTrace(); } } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,email"); request.setParameters(parameters); request.executeAsync(); }
private void getFBUserInfo(final UserDataCallback userDataCallback) { final FBUser fbUser = new FBUser(); GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { try { fbUser.username = object.getString("name"); fbUser.userId = object.getString("id"); userDataCallback.userData(fbUser); } catch (JSONException e) { e.printStackTrace(); } } }); request.executeAsync(); }
public void pageAbout(final String pageId){ GraphRequest request = GraphRequest.newGraphPathRequest( AccessToken.getCurrentAccessToken(), "/"+pageId, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { JSONObject object = response.getJSONObject(); String about = object.optString("about"); pageAbout_tv = (TextView)getActivity().findViewById(R.id.pageAbout); pageAbout_tv.setText(about); String description = object.optString("description"); pageAbout_tv = (TextView)getActivity().findViewById(R.id.pageDescription); pageAbout_tv.setText(about); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "about,description"); request.setParameters(parameters); request.executeAsync(); }
private void getFacebookInfo() { Bundle parameters = new Bundle(); parameters.putString("fields", "picture, first_name, id"); new GraphRequest(AccessToken.getCurrentAccessToken(), "/me", parameters, HttpMethod.GET, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse graphResponse) { JSONObject user = graphResponse.getJSONObject(); ParseUser currentUser = ParseUser.getCurrentUser(); currentUser.put("firstName", user.optString("first_name")); currentUser.put("facebookId", user.optString("id")); currentUser.put("pictureURL", user.optJSONObject("picture").optJSONObject("data").optString("url")); currentUser.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e == null) { Log.i(TAG, "User saved"); setResult(RESULT_OK); finish(); } } }); } }).executeAsync(); }
public void getFurtherInfoAboutMe(final ProfileInformationCallback callback) { GraphRequest.newMeRequest( AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject me, GraphResponse response) { if (response.getError() != null) { // handle error callback.onReady(null); } else { FacebookUser user = getUser(); String email = me.optString("email"); if (email != null) user.email = email; callback.onReady(user); } } }).executeAsync(); }
/** * Attempts to get a list of the user's visible * events from his/her facebook */ private void getEventListFromFacebook() { if (InternetUtil.isOnline(getActivity())) { SessionManager manager = new SessionManager(getActivity()); AccessToken token = manager.getAccessToken(); String path = manager.getString(getString(R.string.fb_field_id)) + "/events"; Bundle params = new Bundle(); params.putString(getString(R.string.fb_fields_key), getString(R.string.fb_ev_fields)); GraphRequest request = GraphRequest.newGraphPathRequest(token, path, this); request.setParameters(params); request.executeAsync(); } else { showNoInternetSnackBar(); } }
private boolean makeMeRequest() { GraphRequest request = GraphRequest.newMeRequest( AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted( JSONObject object, GraphResponse response) { try { facebook.setVisibility(View.VISIBLE); if(object!=null) facebookId = object.getString("id"); } catch (JSONException e1) { e1.printStackTrace(); } } }); request.executeAsync(); return false; }
/** * Creates a new Request configured to create a user owned Open Graph object. * * @param accessToken the accessToken to use, or null * @param openGraphObject the Open Graph object to create; must not be null, and must have a * non-empty type and title * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ public static GraphRequest newPostOpenGraphObjectRequest( AccessToken accessToken, JSONObject openGraphObject, Callback callback) { if (openGraphObject == null) { throw new FacebookException("openGraphObject cannot be null"); } if (Utility.isNullOrEmpty(openGraphObject.optString("type"))) { throw new FacebookException("openGraphObject must have non-null 'type' property"); } if (Utility.isNullOrEmpty(openGraphObject.optString("title"))) { throw new FacebookException("openGraphObject must have non-null 'title' property"); } String path = String.format(MY_OBJECTS_FORMAT, openGraphObject.optString("type")); Bundle bundle = new Bundle(); bundle.putString(OBJECT_PARAM, openGraphObject.toString()); return new GraphRequest(accessToken, path, bundle, HttpMethod.POST, callback); }
/** * Creates a new Request configured to publish an Open Graph action. * * @param accessToken the access token to use, or null * @param openGraphAction the Open Graph action to create; must not be null, and must have a * non-empty 'type' * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ public static GraphRequest newPostOpenGraphActionRequest( AccessToken accessToken, JSONObject openGraphAction, Callback callback) { if (openGraphAction == null) { throw new FacebookException("openGraphAction cannot be null"); } String type = openGraphAction.optString("type"); if (Utility.isNullOrEmpty(type)) { throw new FacebookException("openGraphAction must have non-null 'type' property"); } String path = String.format(MY_ACTION_FORMAT, type); return GraphRequest.newPostRequest(accessToken, path, openGraphAction, callback); }
/** * Creates a new Request configured to update a user owned Open Graph object. * * @param accessToken the access token to use, or null * @param openGraphObject the Open Graph object to update, which must have a valid 'id' * property * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ public static GraphRequest newUpdateOpenGraphObjectRequest( AccessToken accessToken, JSONObject openGraphObject, Callback callback) { if (openGraphObject == null) { throw new FacebookException("openGraphObject cannot be null"); } String path = openGraphObject.optString("id"); if (path == null) { throw new FacebookException("openGraphObject must have an id"); } Bundle bundle = new Bundle(); bundle.putString(OBJECT_PARAM, openGraphObject.toString()); return new GraphRequest(accessToken, path, bundle, HttpMethod.POST, callback); }
/** * Creates a new Request configured to upload a photo to the user's default photo album. The * photo will be read from the specified Uri. * @param accessToken the access token to use, or null * @param photoUri the file:// or content:// Uri to the photo on device. * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws FileNotFoundException */ public static GraphRequest newUploadPhotoRequest( AccessToken accessToken, Uri photoUri, Callback callback) throws FileNotFoundException { if (Utility.isFileUri(photoUri)) { return newUploadPhotoRequest(accessToken, new File(photoUri.getPath()), callback); } else if (!Utility.isContentUri(photoUri)) { throw new FacebookException("The photo Uri must be either a file:// or content:// Uri"); } Bundle parameters = new Bundle(1); parameters.putParcelable(PICTURE_PARAM, photoUri); return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback); }
/** * Creates a new Request configured to upload a photo to the user's default photo album. The * photo will be read from the specified Uri. * @param accessToken the access token to use, or null * @param videoUri the file:// or content:// Uri to the video on device. * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws FileNotFoundException */ public static GraphRequest newUploadVideoRequest( AccessToken accessToken, Uri videoUri, Callback callback) throws FileNotFoundException { if (Utility.isFileUri(videoUri)) { return newUploadVideoRequest(accessToken, new File(videoUri.getPath()), callback); } else if (!Utility.isContentUri(videoUri)) { throw new FacebookException("The video Uri must be either a file:// or content:// Uri"); } Bundle parameters = new Bundle(1); parameters.putParcelable(PICTURE_PARAM, videoUri); return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback); }
/** * Creates a new Request configured to post a status update to a user's feed. * * @param accessToken the access token to use, or null * @param message the text of the status update * @param placeId an optional place id to associate with the post * @param tagIds an optional list of user ids to tag in the post * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ private static GraphRequest newStatusUpdateRequest( AccessToken accessToken, String message, String placeId, List<String> tagIds, Callback callback) { Bundle parameters = new Bundle(); parameters.putString("message", message); if (placeId != null) { parameters.putString("place", placeId); } if (tagIds != null && tagIds.size() > 0) { String tags = TextUtils.join(",", tagIds); parameters.putString("tags", tags); } return new GraphRequest(accessToken, MY_FEED, parameters, HttpMethod.POST, callback); }
/** * Creates a new Request configured to post a status update to a user's feed. * * @param accessToken the access token to use, or null * @param message the text of the status update * @param place an optional place to associate with the post * @param tags an optional list of users to tag in the post * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ public static GraphRequest newStatusUpdateRequest( AccessToken accessToken, String message, JSONObject place, List<JSONObject> tags, Callback callback) { List<String> tagIds = null; if (tags != null) { tagIds = new ArrayList<String>(tags.size()); for (JSONObject tag: tags) { tagIds.add(tag.optString("id")); } } String placeId = place == null ? null : place.optString("id"); return newStatusUpdateRequest(accessToken, message, placeId, tagIds, callback); }
private void shareLinkContent(final ShareLinkContent linkContent, final FacebookCallback<Sharer.Result> callback) { final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { final JSONObject data = response.getJSONObject(); final String postId = (data == null ? null : data.optString("id")); ShareInternalUtility.invokeCallbackWithResults(callback, postId, response); } }; final Bundle parameters = new Bundle(); parameters.putString("link", Utility.getUriString(linkContent.getContentUrl())); parameters.putString("picture", Utility.getUriString(linkContent.getImageUrl())); parameters.putString("name", linkContent.getContentTitle()); parameters.putString("description", linkContent.getContentDescription()); parameters.putString("ref", linkContent.getRef()); new GraphRequest( AccessToken.getCurrentAccessToken(), "/me/feed", parameters, HttpMethod.POST, requestCallback).executeAsync(); }
/** * Metodo para obtener el nombre de usuario y la fotografia de Facebook */ private void ObtenerDatosFacebook() { //Para obtener datos del perfil tenemos que hacer un GraphRequest GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(final JSONObject object, GraphResponse response) { //Obtenemos los datos del perfil Profile perfil = Profile.getCurrentProfile(); //Lo mostramos en pantalla y lo guardamos foto.setProfileId(perfil.getId()); nombre.setText(object.optString("name")); } }); //Añadimos los parametros que hemos requerido y ejecutamos la peticion Bundle parameters = new Bundle(); parameters.putString("fields", "name"); request.setParameters(parameters); request.executeAsync(); }
private GraphRequest.GraphJSONObjectCallback DefaultGraphJSONObjectCallback(final Callback callback) { return new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) { if (graphResponse.getError() != null) { callback.fail(); if (isDebug) { } } else { if (isDebug) { } callback.complete(graphResponse, graphResponse.getJSONObject()); } } }; }