Search in sources :

Example 36 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class PlaceManager method newCurrentPlaceRequest.

/**
 * Creates a new current place request.
 * <p>
 * The current place request estimates the place where the user is currently located.
 * The response contains a list of places and their associated confidence levels.
 * <p>
 * If a location is not specified in {@link CurrentPlaceRequestParams}, then the SDK
 * retrieves the current location using {@link android.location.LocationManager}.
 *
 * @param requestParams the request parameters. See {@link CurrentPlaceRequestParams}
 * @param callback a {@link OnRequestReadyCallback} that is invoked when the
 * {@link GraphRequest} has been created and is ready to be executed.
 */
public static void newCurrentPlaceRequest(final CurrentPlaceRequestParams requestParams, final OnRequestReadyCallback callback) {
    Location location = requestParams.getLocation();
    CurrentPlaceRequestParams.ScanMode scanMode = requestParams.getScanMode();
    LocationPackageRequestParams.Builder builder = new LocationPackageRequestParams.Builder();
    // Don't scan for a location if one is provided.
    builder.setLocationScanEnabled(location == null);
    if (scanMode != null && scanMode == CurrentPlaceRequestParams.ScanMode.LOW_LATENCY) {
        // In low-latency mode, avoid active Wi-Fi scanning which can takes
        // several seconds.
        builder.setWifiActiveScanAllowed(false);
    }
    LocationPackageManager.requestLocationPackage(builder.build(), new LocationPackageManager.Listener() {

        @Override
        public void onLocationPackage(LocationPackage locationPackage) {
            if (locationPackage.locationError != null) {
                callback.onLocationError(getLocationError(locationPackage.locationError));
            } else {
                Bundle parameters = getCurrentPlaceParameters(requestParams, locationPackage);
                GraphRequest graphRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), CURRENT_PLACE_RESULTS, parameters, HttpMethod.GET);
                callback.onRequestReady(graphRequest);
            }
        }
    });
}
Also used : LocationPackageRequestParams(com.facebook.places.internal.LocationPackageRequestParams) GraphRequest(com.facebook.GraphRequest) LocationPackage(com.facebook.places.internal.LocationPackage) Bundle(android.os.Bundle) CurrentPlaceRequestParams(com.facebook.places.model.CurrentPlaceRequestParams) LocationPackageManager(com.facebook.places.internal.LocationPackageManager) Location(android.location.Location)

Example 37 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class PlaceManager method newCurrentPlaceFeedbackRequest.

/**
 * Creates a new current place feedback request.
 * <p>
 * This request allows users to provide feedback on the accuracy of the current place
 * estimate. This information is used to improve the accuracy of our results.
 * <p>
 * Returns a new GraphRequest that is configured to perform a current place feedback request.
 *
 * @param requestParams the request parameters. See {@link CurrentPlaceFeedbackRequestParams}
 * @return a {@link GraphRequest} that is ready to be executed
 * @throws FacebookException thrown if parameters
 * {@link CurrentPlaceFeedbackRequestParams#getPlaceId()},
 * {@link CurrentPlaceFeedbackRequestParams#getTracking()}, or
 * {@link CurrentPlaceFeedbackRequestParams#wasHere()} are missing
 */
public static GraphRequest newCurrentPlaceFeedbackRequest(CurrentPlaceFeedbackRequestParams requestParams) {
    String placeId = requestParams.getPlaceId();
    String tracking = requestParams.getTracking();
    Boolean wasHere = requestParams.wasHere();
    if (tracking == null || placeId == null || wasHere == null) {
        throw new FacebookException("tracking, placeId and wasHere must be specified.");
    }
    Bundle parameters = new Bundle(3);
    parameters.putString(PARAM_TRACKING, tracking);
    parameters.putString(PARAM_PLACE_ID, placeId);
    parameters.putBoolean(PARAM_WAS_HERE, wasHere);
    return new GraphRequest(AccessToken.getCurrentAccessToken(), CURRENT_PLACE_FEEDBACK, parameters, HttpMethod.POST);
}
Also used : GraphRequest(com.facebook.GraphRequest) FacebookException(com.facebook.FacebookException) Bundle(android.os.Bundle)

Example 38 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class TestUserManager method createTestAccount.

private JSONObject createTestAccount(List<String> permissions, Mode mode, String uniqueUserTag) {
    Bundle parameters = new Bundle();
    parameters.putString("installed", "true");
    parameters.putString("permissions", getPermissionsString(permissions));
    parameters.putString("access_token", getAppAccessToken());
    // to delete it at the end.
    if (mode == Mode.SHARED) {
        parameters.putString("name", String.format("Shared %s Testuser", getSharedTestAccountIdentifier(permissions, uniqueUserTag)));
    }
    String graphPath = String.format("%s/accounts/test-users", testApplicationId);
    GraphRequest createUserRequest = new GraphRequest(null, graphPath, parameters, HttpMethod.POST);
    GraphResponse response = createUserRequest.executeAndWait();
    FacebookRequestError error = response.getError();
    JSONObject testAccount = response.getJSONObject();
    if (error != null) {
        return null;
    } else {
        assert testAccount != null;
        // it later.
        if (mode == Mode.SHARED) {
            // the create request.
            try {
                testAccount.put("name", parameters.getString("name"));
            } catch (JSONException e) {
                Log.e(LOG_TAG, "Could not set name", e);
            }
            storeTestAccount(testAccount);
        }
        return testAccount;
    }
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) Bundle(android.os.Bundle) JSONException(org.json.JSONException) FacebookRequestError(com.facebook.FacebookRequestError)

Example 39 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class PlaceManagerTest method testPlaceInfoRequest.

@Test
public void testPlaceInfoRequest() {
    PlaceInfoRequestParams.Builder builder = new PlaceInfoRequestParams.Builder();
    builder.setPlaceId("12345");
    builder.addField("field1");
    builder.addFields(new String[] { "field2", "field3" });
    PlaceInfoRequestParams params = builder.build();
    GraphRequest request = PlaceManager.newPlaceInfoRequest(params);
    assertEquals("12345", request.getGraphPath());
    assertEquals(HttpMethod.GET, request.getHttpMethod());
    Bundle requestParams = request.getParameters();
    assertEquals("field1,field3,field2", requestParams.get("fields"));
}
Also used : GraphRequest(com.facebook.GraphRequest) PlaceInfoRequestParams(com.facebook.places.model.PlaceInfoRequestParams) Bundle(android.os.Bundle) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 40 with GraphRequest

use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.

the class PostsRequest method makeGetPostsRequest.

public static void makeGetPostsRequest(GraphRequest.Callback callback) {
    Bundle params = new Bundle();
    params.putString("fields", "message,created_time,id,picture,story,from");
    GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), FEED_ENDPOINT, params, HttpMethod.GET, callback);
    request.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle)

Aggregations

GraphRequest (com.facebook.GraphRequest)52 Bundle (android.os.Bundle)39 GraphResponse (com.facebook.GraphResponse)25 JSONObject (org.json.JSONObject)22 FacebookException (com.facebook.FacebookException)15 JSONException (org.json.JSONException)15 FacebookRequestError (com.facebook.FacebookRequestError)8 AccessToken (com.facebook.AccessToken)7 FacebookCallback (com.facebook.FacebookCallback)5 Uri (android.net.Uri)4 JSONArray (org.json.JSONArray)4 Test (org.junit.Test)3 Intent (android.content.Intent)2 Location (android.location.Location)2 GraphRequestBatch (com.facebook.GraphRequestBatch)2 Profile (com.facebook.Profile)2 CollectionMapper (com.facebook.internal.CollectionMapper)2 CurrentPlaceFeedbackRequestParams (com.facebook.places.model.CurrentPlaceFeedbackRequestParams)2 PlaceInfoRequestParams (com.facebook.places.model.PlaceInfoRequestParams)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2