com.facebook.Request Java Examples

The following examples show how to use com.facebook.Request. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FriendPickerFragment.java    From KlyphMessenger with MIT License 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #2
Source File: FriendPickerFragment.java    From facebook-api-android-maven with Apache License 2.0 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + friendPickerType.getRequestPath(), null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #3
Source File: FriendPickerFragment.java    From android-skeleton-project with MIT License 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #4
Source File: FriendPickerFragment.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #5
Source File: ProgressOutputStreamTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    r1 = new Request(null, "4");
    r2 = new Request(null, "4");

    progressMap = new HashMap<Request, RequestProgress>();
    progressMap.put(r1, new RequestProgress(null, r1));
    progressMap.get(r1).addToMax(5);
    progressMap.put(r2, new RequestProgress(null, r2));
    progressMap.get(r2).addToMax(5);

    requests = new RequestBatch(r1, r2);

    ByteArrayOutputStream backing = new ByteArrayOutputStream();
    stream = new ProgressOutputStream(backing, requests, progressMap, MAX_PROGRESS);
}
 
Example #6
Source File: FriendPickerFragment.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #7
Source File: LoginActivity.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void call(Session session, SessionState state, Exception exception) {
	if (session.isOpened()) {
		setFacebookSession(session);
		// make request to the /me API
		Request.newMeRequest(session, new Request.GraphUserCallback() {

			// callback after Graph API response with user object
			@Override
			public void onCompleted(GraphUser user, Response response) {
				if (user != null) {
					Toast.makeText(LoginActivity.this,
							"Hello " + user.getName(), Toast.LENGTH_LONG)
							.show();
				}
			}
		}).executeAsync();
	}
}
 
Example #8
Source File: Utility.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
public static FetchedAppSettings queryAppSettings(final String applicationId, final boolean forceRequery) {

        // Cache the last app checked results.
        if (!forceRequery && fetchedAppSettings.containsKey(applicationId)) {
            return fetchedAppSettings.get(applicationId);
        }

        Bundle appSettingsParams = new Bundle();
        appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS));

        Request request = Request.newGraphPathRequest(null, applicationId, null);
        request.setParameters(appSettingsParams);

        GraphObject supportResponse = request.executeAndWait().getGraphObject();
        FetchedAppSettings result = new FetchedAppSettings(
                safeGetBooleanFromResponse(supportResponse, SUPPORTS_ATTRIBUTION),
                safeGetBooleanFromResponse(supportResponse, SUPPORTS_IMPLICIT_SDK_LOGGING),
                safeGetStringFromResponse(supportResponse, NUX_CONTENT),
                safeGetBooleanFromResponse(supportResponse, NUX_ENABLED)
                );

        fetchedAppSettings.put(applicationId, result);

        return result;
    }
 
Example #9
Source File: FriendPickerFragment.java    From Klyph with MIT License 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #10
Source File: Utility.java    From facebook-api-android-maven with Apache License 2.0 6 votes vote down vote up
public static FetchedAppSettings queryAppSettings(final String applicationId, final boolean forceRequery) {

        // Cache the last app checked results.
        if (!forceRequery && fetchedAppSettings.containsKey(applicationId)) {
            return fetchedAppSettings.get(applicationId);
        }

        Bundle appSettingsParams = new Bundle();
        appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS));

        Request request = Request.newGraphPathRequest(null, applicationId, null);
        request.setParameters(appSettingsParams);

        GraphObject supportResponse = request.executeAndWait().getGraphObject();
        FetchedAppSettings result = new FetchedAppSettings(
                safeGetBooleanFromResponse(supportResponse, SUPPORTS_ATTRIBUTION),
                safeGetBooleanFromResponse(supportResponse, SUPPORTS_IMPLICIT_SDK_LOGGING),
                safeGetStringFromResponse(supportResponse, NUX_CONTENT),
                safeGetBooleanFromResponse(supportResponse, NUX_ENABLED)
                );

        fetchedAppSettings.put(applicationId, result);

        return result;
    }
 
Example #11
Source File: FriendPickerFragment.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + friendPickerType.getRequestPath(), null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #12
Source File: FriendPickerFragment.java    From platform-friends-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #13
Source File: PickerFragment.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
private void loadDataSkippingRoundTripIfCached() {
    clearResults();

    Request request = getRequestForLoadData(getSession());
    if (request != null) {
        onLoadingData();
        loadingStrategy.startLoading(request);
    }
}
 
Example #14
Source File: PickerFragment.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
private void loadDataSkippingRoundTripIfCached() {
    clearResults();

    Request request = getRequestForLoadData(getSession());
    if (request != null) {
        onLoadingData();
        loadingStrategy.startLoading(request);
    }
}
 
Example #15
Source File: FriendPickerFragment.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example #16
Source File: FriendPickerFragment.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example #17
Source File: LoginButton.java    From KlyphMessenger with MIT License 5 votes vote down vote up
private void fetchUserInfo() {
    if (fetchUserInfo) {
        final Session currentSession = sessionTracker.getOpenSession();
        if (currentSession != null) {
            if (currentSession != userInfoSession) {
                Request request = Request.newMeRequest(currentSession, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser me,  Response response) {
                        if (currentSession == sessionTracker.getOpenSession()) {
                            user = me;
                            if (userInfoChangedCallback != null) {
                                userInfoChangedCallback.onUserInfoFetched(user);
                            }
                        }
                        if (response.getError() != null) {
                            handleError(response.getError().getException());
                        }
                    }
                });
                Request.executeBatchAsync(request);
                userInfoSession = currentSession;
            }
        } else {
            user = null;
            if (userInfoChangedCallback != null) {
                userInfoChangedCallback.onUserInfoFetched(user);
            }
        }
    }
}
 
Example #18
Source File: FriendPickerFragment.java    From KlyphMessenger with MIT License 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example #19
Source File: FriendPickerFragment.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example #20
Source File: FacebookShareActivity.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
private void postImageToFacebook() {
    Session session = Session.getActiveSession();
    final Uri uri = (Uri) mExtras.get(Intent.EXTRA_STREAM);
    final String extraText = mPostTextView.getText().toString();
    if (session.isPermissionGranted("publish_actions"))
    {
        Bundle param = new Bundle();

        // Add the image
        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            byte[] byteArrayData = stream.toByteArray();
            param.putByteArray("picture", byteArrayData);
        } catch (IOException ioe) {
            // The image that was send through is now not there?
            Assert.assertTrue(false);
        }

        // Add the caption
        param.putString("message", extraText);
        Request request = new Request(session,"me/photos", param, HttpMethod.POST, new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                addNotification(getString(R.string.photo_post), response.getGraphObject(), response.getError());

            }
        }, null);
        RequestAsyncTask asyncTask = new RequestAsyncTask(request);
        asyncTask.execute();
        finish();
    }
}
 
Example #21
Source File: KlyphPlacePickerFragment.java    From Klyph with MIT License 5 votes vote down vote up
private Request createRequest(Location location, int radiusInMeters, int resultsLimit, String searchText,
        Set<String> extraFields,
        Session session) {
    Request request = Request.newPlacesSearchRequest(session, location, radiusInMeters, resultsLimit, searchText,
            null);

    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[]{
            ID,
            NAME,
            LOCATION,
            CATEGORY,
            WERE_HERE_COUNT
    };
    fields.addAll(Arrays.asList(requiredFields));

    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}
 
Example #22
Source File: FacebookContactMatcher.java    From buddycloud-android with Apache License 2.0 5 votes vote down vote up
protected void getFriends(final Context context, final Session session, 
		final GraphUser user, final ModelCallback<JSONArray> callback) {
	Request.newGraphPathRequest(session, "/me/friends", new Callback() {
		@Override
		public void onCompleted(Response response) {
			if (response.getError() != null) {
				callback.error(response.getError().getException());
				return;
			}
			matchContacts(context, user, response, callback);
		}
	}).executeAsync();
}
 
Example #23
Source File: FriendPickerFragment.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example #24
Source File: FiscalizacaoConcluidaActivity.java    From vocefiscal-android with Apache License 2.0 5 votes vote down vote up
private void publishStory(Session session) 
{
	Bundle postParams = new Bundle();
	postParams.putString("name", "Você Fiscal");

	// Receber os dados da eleição!!!
	postParams.putString("message", "Eu fiscalizei a seção: "+ this.secao +"\nNa zona eleitoral: " + this.zonaEleitoral + "\nNo município de: " + this.municipio);			
	postParams.putString("description", "Obrigado por contribuir com a democracia!");
	postParams.putString("link", "http://www.vocefiscal.org/");
	postParams.putString("picture", "http://imagizer.imageshack.us/v2/150x100q90/913/bAwPgx.png");

	Request.Callback callback= new Request.Callback() 
	{
		public void onCompleted(Response response) 
		{
			JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
			String postId = "Compartilhado com sucesso!";
			try 
			{
				postId = graphResponse.getString("Compartilhado com sucesso!");
			} catch (JSONException e) 
			{
			}
			FacebookRequestError error = response.getError();
			if (error != null) 
			{
				Toast.makeText(FiscalizacaoConcluidaActivity.this.getApplicationContext(),error.getErrorMessage(),Toast.LENGTH_SHORT).show();
			} else 
			{
				Toast.makeText(FiscalizacaoConcluidaActivity.this.getApplicationContext(),	postId,	Toast.LENGTH_LONG).show();
			}
		}
	};

	Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);

	RequestAsyncTask task = new RequestAsyncTask(request);
	task.execute();
}
 
Example #25
Source File: FacebookContactMatcher.java    From buddycloud-android with Apache License 2.0 5 votes vote down vote up
private void getFriends(final Context context, final Session session, 
		final ModelCallback<JSONArray> callback) {
	Request.newMeRequest(session, new GraphUserCallback() {
		@Override
		public void onCompleted(final GraphUser user, Response response) {
			if (response.getError() != null) {
				callback.error(response.getError().getException());
				return;
			}
			getFriends(context, session, user, callback);
		}
	}).executeAsync();
}
 
Example #26
Source File: LoginButton.java    From Klyph with MIT License 5 votes vote down vote up
private void fetchUserInfo() {
    if (fetchUserInfo) {
        final Session currentSession = sessionTracker.getOpenSession();
        if (currentSession != null) {
            if (currentSession != userInfoSession) {
                Request request = Request.newMeRequest(currentSession, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser me,  Response response) {
                        if (currentSession == sessionTracker.getOpenSession()) {
                            user = me;
                            if (userInfoChangedCallback != null) {
                                userInfoChangedCallback.onUserInfoFetched(user);
                            }
                        }
                        if (response.getError() != null) {
                            handleError(response.getError().getException());
                        }
                    }
                });
                Request.executeBatchAsync(request);
                userInfoSession = currentSession;
            }
        } else {
            user = null;
            if (userInfoChangedCallback != null) {
                userInfoChangedCallback.onUserInfoFetched(user);
            }
        }
    }
}
 
Example #27
Source File: FriendPickerFragment.java    From Klyph with MIT License 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example #28
Source File: FlowApiRequests.java    From flow-android with MIT License 5 votes vote down vote up
public static void getUserCoverImage(final Context context, final String fbid, final ImageView imageView, final FlowImageLoaderCallback callback){
    Bundle params = new Bundle();
    params.putString("fields", "cover");
    new Request(
            Session.getActiveSession(),
            "/" + fbid,
            params,
            HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {
                    GraphObject graphObject = response.getGraphObject();
                    if (graphObject != null && graphObject.getProperty("cover") != null) {
                        if (graphObject != null && graphObject.getProperty("cover") != null) {
                            try {
                                JSONObject json = graphObject.getInnerJSONObject();
                                String url = json.getJSONObject("cover").getString("source");
                                FlowImageLoader loader = new FlowImageLoader(context);
                                loader.loadImage(url, imageView, callback);
                            } catch (Exception e) {
                                Crashlytics.logException(e);
                            }
                        }
                    }
                }
            }
    ).executeAsync();
}
 
Example #29
Source File: FacebookGraphAPIRequestTask.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * This is the method performing all of this Tasks' work. It loops through all of the {@link com.dhsoftware.android.FacebookNewsfeedSample.model.GraphAPIRequest GraphAPIRequest}s and
 * adds all the downloaded items into a list.
 */
@Override
protected Void doInBackground(GraphAPIRequest... params) {
   mItems = new ArrayList<INewsfeedItem>();
   final Session session = Session.getActiveSession();
   for (GraphAPIRequest request : params) {
      Request graphApiRequest = Request.newGraphPathRequest(session, request.getGraphPath(), null);
      graphApiRequest.setParameters(request.getParameters());
      // this call blocks the calling thread, but in this case it's OK, since we're already in a background thread
      // in this way, you can see both uses of making requests to the Facebook API
      Response response = graphApiRequest.executeAndWait();
      // we could also check here that our Session's valid; which is recommended in Facebook's own samples
      // in this sample's case, I check it in MyNewsfeedFragment just before adding the downloaded items to the Adapter
      if (response != null) {
         // if we did get a response, we
         processResponse(response.getGraphObject().getInnerJSONObject());
      }

   }

   // We sort all items we've downloaded from newest to oldest,
   // in this way, the items will fill in naturally to how we display
   // Newsfeed items.
   Collections.sort(mItems, new Comparator<INewsfeedItem>() {
      @Override
      public int compare(INewsfeedItem lhs, INewsfeedItem rhs) {
         DateTime lhsDateTime = new DateTime(lhs.getCreated_Time());
         DateTime rhsDateTime = new DateTime(rhs.getCreated_Time());
         return (lhsDateTime.compareTo(rhsDateTime));
      }
   });

   // this is not the method returning the objects,
   // since we're still running in a background thread
   return null;
}
 
Example #30
Source File: FriendPickerFragment.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}