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);
}
}
});
}
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);
}
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;
}
}
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"));
}
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();
}
Aggregations