I'm currently developing a feature in my application that will allow users to invite their Facebook friends and for that they and the friend will receive a reward/gift.
So for that purpose I using the Facebook request option. So I went over the following 2 docs:
https://developers.facebook.com/docs/android/send-requests/
https://developers.facebook.com/docs/android/app-link-requests/
Now this works great if both devices have the application installed and I send request from one to another and can retrieve additional data that the sender sent using this method:
private void getRequestData(final String inRequestId) {
// Create a new request for an HTTP GET with the
// request ID as the Graph path.
Request request = new Request(Session.getActiveSession(),
inRequestId, null, HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
// Process the returned response
GraphObject graphObject = response.getGraphObject();
FacebookRequestError error = response.getError();
// Default message
String message = "Incoming request";
if (graphObject != null)
{
CupsLog.d(TAG, "getRequestData -> graphObject != null: "+ graphObject.toString());
// Check if there is extra data
if (graphObject.getProperty("data") != null)
{
CupsLog.d(TAG, "getRequestData -> graphObject.getProperty(data) != null");
try
{
// Get the data, parse info to get the key/value info
JSONObject dataObject = new JSONObject((String)graphObject.getProperty("data"));
// Get the value for the key - badge_of_awesomeness
String reward = dataObject.getString("reward");
// Get the value for the key - social_karma
String coffeeCups = dataObject.getString("coffee_cups");
// Get the sender's name
JSONObject fromObject = (JSONObject) graphObject.getProperty("from");
String sender = fromObject.getString("name");
String title = sender+" sent you a gift";
// Create the text for the alert based on the sender
// and the data
message = title + "\n\n" +
"reward: " + reward +
" coffeeCups: " + coffeeCups;
} catch (JSONException e) {
message = "Error getting request info";
}
} else if (error != null) {
message = "Error getting request info";
}
else
{
CupsLog.d(TAG, "getRequestData -> graphObject.getProperty(data) == null");
}
}
Toast.makeText(SocialFeaturesActivity.this, message, Toast.LENGTH_LONG).show();
}
});
// Execute the request asynchronously.
Request.executeBatchAsync(request);
}
The question: If the receiver will get this request in Facebook, but will not have it installed, this request will redirect him to Google Play to install the app. After he installs the app and open it for the first time? Is there s way to receive this data anyway?
Facebook suggest that the receiver should check every time the app opens if there are pending requests (using
onResume
). You can check it using the/{user-id}/apprequests
endpoint as shown in:https://developers.facebook.com/docs/graph-api/reference/user/apprequests/
According to its documentation, a GET will return an array of request objects.
Once you obtained the request ids, you may gather additional information using
/{request-id}
https://developers.facebook.com/docs/graph-api/reference/request/
After processing the request, delete it to avoid duplicates.
Because Facebook does not delete the request until you explicitly do so, you do not need server side code for this interaction.