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 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(); }
@Override public void onCompleted(JSONObject object, GraphResponse response) { try { SocialUser user = new SocialUser(); user.userId = object.getString("id"); user.accessToken = AccessToken.getCurrentAccessToken().getToken(); user.photoUrl = String.format(PHOTO_URL, user.userId); SocialUser.Profile profile = new SocialUser.Profile(); profile.email = object.has("email")? object.getString("email") : ""; profile.name = object.has("name")? object.getString("name"): ""; profile.pageLink = object.has("link")? object.getString("link"): ""; user.profile = profile; SocialLoginManager.getInstance(this).onLoginSuccess(user); } catch (JSONException e) { SocialLoginManager.getInstance(this).onLoginError(e.getCause()); } LoginManager.getInstance().logOut(); finish(); }
@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()); }
@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(); }
private List<Profile> transform(GraphResponse response) { Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new GsonDateTypeAdapter()) .create(); String data = null; try { data = response.getJSONObject().has("data") ? response.getJSONObject().get("data").toString() : response.getJSONObject().toString(); } catch (JSONException e) { e.printStackTrace(); } Type listType = new TypeToken<List<Profile>>() { }.getType(); return gson.fromJson(data, listType); }
private List<Photo> transform(GraphResponse response) { Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new GsonDateTypeAdapter()) .create(); String data = null; try { data = response.getJSONObject().has("data") ? response.getJSONObject().get("data").toString() : response.getJSONObject().toString(); } catch (JSONException e) { e.printStackTrace(); throw new JsonParseException(e); } Type listType = new TypeToken<List<Photo>>() { }.getType(); return gson.fromJson(data, listType); }
private List<Album> parseAlbums(GraphResponse response) { Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new GsonDateTypeAdapter()) .create(); String data = null; try { data = response.getJSONObject().has("data") ? response.getJSONObject().get("data").toString() : response.getJSONObject().toString(); } catch (JSONException e) { e.printStackTrace(); } Type listType = new TypeToken<List<Album>>() { }.getType(); return gson.fromJson(data, listType); }
@Override public void onCompleted(GraphResponse response) { FacebookRequestError error = response.getError(); if (error != null) { Logger.logError(RequestAction.class, "Failed to get what you have requested", error.getException()); if (mSingleEmitter != null) { mSingleEmitter.onError(error.getException()); } } else { if (response.getRawResponse() == null) { Logger.logError(RequestAction.class, "The response GraphObject " + "has null value. Response=" + response.toString(), null); mSingleEmitter.onError(new FacebookGraphResponseException(response, "The response has null value")); } else { if (mSingleEmitter != null) { mSingleEmitter.onSuccess(response); } } } }
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(); }
/** * Parses the response fetched from Facebook * @param response response from Facebook's event end point * @return a map from event names to events */ public static Map<String, FBEvent> getEventMap(GraphResponse response) { Map<String, FBEvent> events = new HashMap<>(); try { JSONObject jsonResponse = response.getJSONObject(); JSONArray data = jsonResponse.getJSONArray(DATA_KEY); for (int i = 0; i < data.length(); i++) { JSONObject fbEventJson = data.getJSONObject(i); events.put(fbEventJson.getString(NAME_KEY), new FBEvent(fbEventJson)); } } catch(JSONException e) { e.printStackTrace(); } return events; }
@Override public void onCompleted(GraphResponse graphResponse) { final Map<String, FBEvent> events = ParseUtil.getEventMap(graphResponse); new MaterialDialog.Builder(getActivity()) .title(R.string.fb_event_chooser_title) .items(events.keySet().toArray(new CharSequence[0])) .positiveText(R.string.okay) .negativeText(R.string.cancel) .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog d, View view, int which, CharSequence text) { fillFields(events.get(text)); return true; } }) .show(); }
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; }
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 void getFansPage() { Bundle bundle = new Bundle(); bundle.putString("fields", "picture,full_picture,from,actions,message,link,created_time,updated_time,comments,likes"); facebookTool.getFeed(fb_id, bundle, new FacebookTool.Callback() { // facebookTool.getFeed(fb_id, new FacebookTool.Callback() { @Override public void complete(GraphResponse graphResponse, JSONObject jsonObject) { Logger.d(jsonObject.toString()); Gson gson = new Gson(); Feed feed = gson.fromJson(jsonObject.toString(), Feed.class); setData(feed.getData()); } @Override public void fail() { Logger.d("fail"); } }); }
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()); } } }; }
/** * @param callback * @return */ private GraphRequest.Callback DefaultCallback(final Callback callback) { GraphRequest.Callback GraphRequestcallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse graphResponse) { if (graphResponse.getError() != null) { callback.fail(); if (isDebug) { } } else { if (isDebug) { } callback.complete(graphResponse, graphResponse.getJSONObject()); } } }; return GraphRequestcallback; }
private void fetchAlbums() { GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { progressBar.setVisibility(View.GONE); try { final List<String> urls = parseAlbumData(object.getJSONObject("albums").getJSONArray("data")); if (urls.isEmpty()) { Toast.makeText(PhotosActivity.this, "You have no albums on Facebook!", Toast.LENGTH_LONG).show(); return; } photos.clear(); photos.addAll(urls); adapter.notifyDataSetChanged(); } catch (Exception e) { e.printStackTrace(); } } }); Bundle parameters = new Bundle(); parameters.putString("fields", "name,albums.limit(100){name,picture{url}}"); request.setParameters(parameters); request.executeAsync(); }
private void fillList() { AccessToken accessToken = AccessToken.getCurrentAccessToken(); if (accessToken == null) Log.d("MARAUDERSMAP", "ACCESS TOKEN IS NULL, MAKING REQUEST"); GraphRequest request = GraphRequest.newMyFriendsRequest(accessToken, new GraphRequest.GraphJSONArrayCallback() { @Override public void onCompleted(JSONArray jsonArray, GraphResponse graphResponse) { int numFriends = jsonArray.length(); for(int i = 0; i < numFriends; i++){ try { FacebookFriend friend = new FacebookFriend(jsonArray.getJSONObject(i)); SelectFriendFragment.this.friendsList.add(friend); } catch (JSONException e) { e.printStackTrace(); } } SelectFriendsArrayAdapter friendsArrayAdapter = new SelectFriendsArrayAdapter(getActivity(), friendsList); SelectFriendFragment.this.setListAdapter(friendsArrayAdapter); } } ); request.executeAsync(); }
@Override public void onSuccess(final LoginResult loginResult) { if (loginResult.getRecentlyGrantedPermissions().contains("email")) { GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject me, GraphResponse response) { if (response.getError() != null) { Toast.makeText(getActivity(), getString(R.string.signin_fail_error), Toast.LENGTH_SHORT).show(); } else { onFacebookLogin(loginResult.getAccessToken().getToken()); } } }).executeAsync(); } else { Toast.makeText(getActivity(), getString(R.string.signin_fail_error), Toast.LENGTH_SHORT).show(); } }
public void requestFacebookCoverPhoto(AccessToken accessToken, final FacebookGetLoginUserCallback callback) { if (NetworkUtils.getInstance().isOnline()) { Bundle params = new Bundle(); params.putString("fields", "cover"); GraphRequest request = new GraphRequest( accessToken, "me", params, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { try { JSONObject coverResponse = response.getJSONObject().getJSONObject("cover"); String coverUrl = coverResponse.getString("source"); UserModel.getInstance().addFacebookCoverUrl(coverUrl); callback.onSuccess(); } catch (JSONException e) { e.printStackTrace(); } } } ); request.executeAsync(); } }
public void requestFacebookProfilePhoto(AccessToken accessToken, final FacebookGetLoginUserCallback callback) { if (NetworkUtils.getInstance().isOnline()) { Bundle params = new Bundle(); params.putString("redirect", "false"); params.putString("type", "large"); GraphRequest request = new GraphRequest( accessToken, "me/picture", params, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { try { String profilePhotoUrl = response.getJSONObject().getJSONObject("data").getString("url"); UserModel.getInstance().addFacebookProfileUrl(profilePhotoUrl); callback.onSuccess(); } catch (JSONException e) { e.printStackTrace(); } } } ); request.executeAsync(); } }