Java Code Examples for com.facebook.model.GraphObject#setProperty()
The following examples show how to use
com.facebook.model.GraphObject#setProperty() .
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: Utility.java From facebook-api-android-maven with Apache License 2.0 | 6 votes |
public static void setAppEventExtendedDeviceInfoParameters(GraphObject params, Context appContext) { JSONArray extraInfoArray = new JSONArray(); extraInfoArray.put(EXTRA_APP_EVENTS_INFO_FORMAT_VERSION); // Application Manifest info: String pkgName = appContext.getPackageName(); int versionCode = -1; String versionName = ""; try { PackageInfo pi = appContext.getPackageManager().getPackageInfo(pkgName, 0); versionCode = pi.versionCode; versionName = pi.versionName; } catch (PackageManager.NameNotFoundException e) { // Swallow } // Application Manifest info: extraInfoArray.put(pkgName); extraInfoArray.put(versionCode); extraInfoArray.put(versionName); params.setProperty("extinfo", extraInfoArray.toString()); }
Example 2
Source File: Utility.java From android-skeleton-project with MIT License | 6 votes |
public static void setAppEventAttributionParameters(GraphObject params, AttributionIdentifiers attributionIdentifiers, String hashedDeviceAndAppId, boolean limitEventUsage) { // Send attributionID if it exists, otherwise send a hashed device+appid specific value as the advertiser_id. if (attributionIdentifiers != null && attributionIdentifiers.getAttributionId() != null) { params.setProperty("attribution", attributionIdentifiers.getAttributionId()); } if (attributionIdentifiers != null && attributionIdentifiers.getAndroidAdvertiserId() != null) { params.setProperty("advertiser_id", attributionIdentifiers.getAndroidAdvertiserId()); params.setProperty("advertiser_tracking_enabled", !attributionIdentifiers.isTrackingLimited()); } else if (hashedDeviceAndAppId != null) { params.setProperty("advertiser_id", hashedDeviceAndAppId); } params.setProperty("application_tracking_enabled", !limitEventUsage); }
Example 3
Source File: Utility.java From FacebookImageShareIntent with MIT License | 6 votes |
public static void setAppEventAttributionParameters(GraphObject params, AttributionIdentifiers attributionIdentifiers, String hashedDeviceAndAppId, boolean limitEventUsage) { // Send attributionID if it exists, otherwise send a hashed device+appid specific value as the advertiser_id. if (attributionIdentifiers != null && attributionIdentifiers.getAttributionId() != null) { params.setProperty("attribution", attributionIdentifiers.getAttributionId()); } if (attributionIdentifiers != null && attributionIdentifiers.getAndroidAdvertiserId() != null) { params.setProperty("advertiser_id", attributionIdentifiers.getAndroidAdvertiserId()); params.setProperty("advertiser_tracking_enabled", !attributionIdentifiers.isTrackingLimited()); } else if (hashedDeviceAndAppId != null) { params.setProperty("advertiser_id", hashedDeviceAndAppId); } params.setProperty("application_tracking_enabled", !limitEventUsage); }
Example 4
Source File: Utility.java From Abelana-Android with Apache License 2.0 | 6 votes |
public static void setAppEventExtendedDeviceInfoParameters(GraphObject params, Context appContext) { JSONArray extraInfoArray = new JSONArray(); extraInfoArray.put(EXTRA_APP_EVENTS_INFO_FORMAT_VERSION); // Application Manifest info: String pkgName = appContext.getPackageName(); int versionCode = -1; String versionName = ""; try { PackageInfo pi = appContext.getPackageManager().getPackageInfo(pkgName, 0); versionCode = pi.versionCode; versionName = pi.versionName; } catch (PackageManager.NameNotFoundException e) { // Swallow } // Application Manifest info: extraInfoArray.put(pkgName); extraInfoArray.put(versionCode); extraInfoArray.put(versionName); params.setProperty("extinfo", extraInfoArray.toString()); }
Example 5
Source File: AuthorizationClientTests.java From FacebookImageShareIntent with MIT License | 6 votes |
@Override Request createGetPermissionsRequest(String accessToken) { final List<String> permissions = permissionsToReport; return new MockRequest() { @Override public Response createResponse() { GraphObject permissionsObject = GraphObject.Factory.create(); if (permissions != null) { for (String permission : permissions) { permissionsObject.setProperty(permission, 1); } } GraphObjectList<GraphObject> data = GraphObject.Factory.createList(GraphObject.class); data.add(permissionsObject); GraphMultiResult result = GraphObject.Factory.create(GraphMultiResult.class); result.setProperty("data", data); return new Response(this, null, null, result, false); } }; }
Example 6
Source File: Utility.java From Abelana-Android with Apache License 2.0 | 6 votes |
public static void setAppEventAttributionParameters(GraphObject params, AttributionIdentifiers attributionIdentifiers, String hashedDeviceAndAppId, boolean limitEventUsage) { // Send attributionID if it exists, otherwise send a hashed device+appid specific value as the advertiser_id. if (attributionIdentifiers != null && attributionIdentifiers.getAttributionId() != null) { params.setProperty("attribution", attributionIdentifiers.getAttributionId()); } if (attributionIdentifiers != null && attributionIdentifiers.getAndroidAdvertiserId() != null) { params.setProperty("advertiser_id", attributionIdentifiers.getAndroidAdvertiserId()); params.setProperty("advertiser_tracking_enabled", !attributionIdentifiers.isTrackingLimited()); } else if (hashedDeviceAndAppId != null) { params.setProperty("advertiser_id", hashedDeviceAndAppId); } params.setProperty("application_tracking_enabled", !limitEventUsage); }
Example 7
Source File: FacebookDialog.java From facebook-api-android-maven with Apache License 2.0 | 5 votes |
void updateObjectAttachmentUrls(String objectProperty, List<String> attachmentUrls, boolean isUserGenerated) { final OpenGraphObject object; try { object = action.getPropertyAs(objectProperty, OpenGraphObject.class); if (object == null) { throw new IllegalArgumentException("Action does not contain a property '" + objectProperty + "'"); } } catch (FacebookGraphObjectException exception) { throw new IllegalArgumentException("Property '" + objectProperty + "' is not a graph object"); } if (!object.getCreateObject()) { throw new IllegalArgumentException( "The Open Graph object in '" + objectProperty + "' is not marked for creation"); } GraphObjectList<GraphObject> attachments = object.getImage(); if (attachments == null) { attachments = GraphObject.Factory.createList(GraphObject.class); } for (String url : attachmentUrls) { GraphObject graphObject = GraphObject.Factory.create(); graphObject.setProperty(NativeProtocol.IMAGE_URL_KEY, url); if (isUserGenerated) { graphObject.setProperty(NativeProtocol.IMAGE_USER_GENERATED_KEY, true); } attachments.add(graphObject); } object.setImage(attachments); }
Example 8
Source File: Utility.java From KlyphMessenger with MIT License | 5 votes |
public static void setAppEventAttributionParameters(GraphObject params, String attributionId, String hashedDeviceAndAppId, boolean limitEventUsage) { // Send attributionID if it exists, otherwise send a hashed device+appid specific value as the advertiser_id. if (attributionId != null) { params.setProperty("attribution", attributionId); } else if (hashedDeviceAndAppId != null) { params.setProperty("advertiser_id", hashedDeviceAndAppId); } params.setProperty("application_tracking_enabled", !limitEventUsage); }
Example 9
Source File: Utility.java From barterli_android with Apache License 2.0 | 5 votes |
public static void setAppEventAttributionParameters(GraphObject params, String attributionId, String hashedDeviceAndAppId, boolean limitEventUsage) { // Send attributionID if it exists, otherwise send a hashed device+appid specific value as the advertiser_id. if (attributionId != null) { params.setProperty("attribution", attributionId); } else if (hashedDeviceAndAppId != null) { params.setProperty("advertiser_id", hashedDeviceAndAppId); } params.setProperty("application_tracking_enabled", !limitEventUsage); }
Example 10
Source File: FacebookDialog.java From Abelana-Android with Apache License 2.0 | 5 votes |
void updateObjectAttachmentUrls(String objectProperty, List<String> attachmentUrls, boolean isUserGenerated) { final OpenGraphObject object; try { object = action.getPropertyAs(objectProperty, OpenGraphObject.class); if (object == null) { throw new IllegalArgumentException("Action does not contain a property '" + objectProperty + "'"); } } catch (FacebookGraphObjectException exception) { throw new IllegalArgumentException("Property '" + objectProperty + "' is not a graph object"); } if (!object.getCreateObject()) { throw new IllegalArgumentException( "The Open Graph object in '" + objectProperty + "' is not marked for creation"); } GraphObjectList<GraphObject> attachments = object.getImage(); if (attachments == null) { attachments = GraphObject.Factory.createList(GraphObject.class); } for (String url : attachmentUrls) { GraphObject graphObject = GraphObject.Factory.create(); graphObject.setProperty(NativeProtocol.IMAGE_URL_KEY, url); if (isUserGenerated) { graphObject.setProperty(NativeProtocol.IMAGE_USER_GENERATED_KEY, true); } attachments.add(graphObject); } object.setImage(attachments); }
Example 11
Source File: GraphRequestTests.java From FacebookImageShareIntent with MIT License | 5 votes |
@LargeTest public void testCommentRoundTrip() { TestSession session = openTestSessionWithSharedUser(); GraphObject status = createStatusUpdate(""); GraphObject createdStatus = batchCreateAndGet(session, "me/feed", status, null, GraphObject.class); String statusID = (String) createdStatus.getProperty("id"); GraphObject comment = GraphObject.Factory.create(); final String commentMessage = "It truly is a wonderful status update."; comment.setProperty("message", commentMessage); GraphObject createdComment1 = batchCreateAndGet(session, statusID + "/comments", comment, null, GraphObject.class); assertNotNull(createdComment1); String comment1ID = (String) createdComment1.getProperty("id"); String comment1Message = (String) createdComment1.getProperty("message"); assertNotNull(comment1ID); assertNotNull(comment1Message); assertEquals(commentMessage, comment1Message); // Try posting the same comment to the same status update. We need to clear its ID first. createdComment1.removeProperty("id"); GraphObject createdComment2 = batchCreateAndGet(session, statusID + "/comments", createdComment1, null, GraphObject.class); assertNotNull(createdComment2); String comment2ID = (String) createdComment2.getProperty("id"); String comment2Message = (String) createdComment2.getProperty("message"); assertNotNull(comment2ID); assertFalse(comment1ID.equals(comment2ID)); assertNotNull(comment2Message); assertEquals(commentMessage, comment2Message); }
Example 12
Source File: FacebookActivityTestCase.java From FacebookImageShareIntent with MIT License | 5 votes |
protected GraphObject createStatusUpdate(String unique) { GraphObject statusUpdate = GraphObject.Factory.create(); String message = String.format( "Check out my awesome new status update posted at: %s. Some chars for you: +\"[]:,%s", new Date(), unique); statusUpdate.setProperty("message", message); return statusUpdate; }
Example 13
Source File: Settings.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 4 votes |
/** * Manually publish install attribution to the Facebook graph. Internally handles caching repeat calls to prevent * multiple installs being published to the graph. * @param context the current Context * @param applicationId the fb application being published. * @return returns a Response object, carrying the server response, or an error. */ public static Response publishInstallAndWaitForResponse(final Context context, final String applicationId) { try { if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } String attributionId = Settings.getAttributionId(context.getContentResolver()); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId+"ping"; String jsonKey = applicationId+"json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); publishParams.setProperty(ATTRIBUTION_KEY, attributionId); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0); } else { return new Response(null, null, graphObject, true); } } else if (attributionId == null) { throw new FacebookException("No attribution id returned from the Facebook application"); } else { if (!Utility.queryAppAttributionSupportAndWait(applicationId)) { throw new FacebookException("Install attribution has been disabled on the server."); } Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.commit(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }
Example 14
Source File: Settings.java From Abelana-Android with Apache License 2.0 | 4 votes |
static Response publishInstallAndWaitForResponse( final Context context, final String applicationId, final boolean isAutoPublish) { try { if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } AttributionIdentifiers identifiers = AttributionIdentifiers.getAttributionIdentifiers(context); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId+"ping"; String jsonKey = applicationId+"json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); // prevent auto publish from occurring if we have an explicit call. if (!isAutoPublish) { setShouldAutoPublishInstall(false); } GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); Utility.setAppEventAttributionParameters(publishParams, identifiers, Utility.getHashedDeviceAndAppID(context, applicationId), getLimitEventAndDataUsage(context)); publishParams.setProperty(AUTO_PUBLISH, isAutoPublish); publishParams.setProperty("application_package_name", context.getPackageName()); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0); } else { return new Response(null, null, null, graphObject, true); } } else if (identifiers == null || (identifiers.getAndroidAdvertiserId() == null && identifiers.getAttributionId() == null)) { throw new FacebookException("No attribution id available to send to server."); } else { if (!Utility.queryAppSettings(applicationId, false).supportsAttribution()) { throw new FacebookException("Install attribution has been disabled on the server."); } Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.commit(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }
Example 15
Source File: Settings.java From HypFacebook with BSD 2-Clause "Simplified" License | 4 votes |
/** * Manually publish install attribution to the Facebook graph. Internally handles caching repeat calls to prevent * multiple installs being published to the graph. * @param context the current Context * @param applicationId the fb application being published. * @return returns a Response object, carrying the server response, or an error. */ public static Response publishInstallAndWaitForResponse(final Context context, final String applicationId) { try { if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } String attributionId = Settings.getAttributionId(context.getContentResolver()); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId+"ping"; String jsonKey = applicationId+"json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); publishParams.setProperty(ATTRIBUTION_KEY, attributionId); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0); } else { return new Response(null, null, graphObject, true); } } else if (attributionId == null) { throw new FacebookException("No attribution id returned from the Facebook application"); } else { if (!Utility.queryAppAttributionSupportAndWait(applicationId)) { throw new FacebookException("Install attribution has been disabled on the server."); } Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.commit(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }
Example 16
Source File: Settings.java From FacebookImageShareIntent with MIT License | 4 votes |
static Response publishInstallAndWaitForResponse( final Context context, final String applicationId, final boolean isAutoPublish) { try { if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } AttributionIdentifiers identifiers = AttributionIdentifiers.getAttributionIdentifiers(context); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId+"ping"; String jsonKey = applicationId+"json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); // prevent auto publish from occurring if we have an explicit call. if (!isAutoPublish) { setShouldAutoPublishInstall(false); } GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); Utility.setAppEventAttributionParameters(publishParams, identifiers, Utility.getHashedDeviceAndAppID(context, applicationId), getLimitEventAndDataUsage(context)); publishParams.setProperty(AUTO_PUBLISH, isAutoPublish); publishParams.setProperty("application_package_name", context.getPackageName()); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0); } else { return new Response(null, null, null, graphObject, true); } } else if (identifiers.getAndroidAdvertiserId() == null && identifiers.getAttributionId() == null) { throw new FacebookException("No attribution id available to send to server."); } else { if (!Utility.queryAppSettings(applicationId, false).supportsAttribution()) { throw new FacebookException("Install attribution has been disabled on the server."); } Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.commit(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }
Example 17
Source File: Settings.java From android-skeleton-project with MIT License | 4 votes |
static Response publishInstallAndWaitForResponse( final Context context, final String applicationId, final boolean isAutoPublish) { try { if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } AttributionIdentifiers identifiers = AttributionIdentifiers.getAttributionIdentifiers(context); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId+"ping"; String jsonKey = applicationId+"json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); // prevent auto publish from occurring if we have an explicit call. if (!isAutoPublish) { setShouldAutoPublishInstall(false); } GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); Utility.setAppEventAttributionParameters(publishParams, identifiers, Utility.getHashedDeviceAndAppID(context, applicationId), getLimitEventAndDataUsage(context)); publishParams.setProperty(AUTO_PUBLISH, isAutoPublish); publishParams.setProperty("application_package_name", context.getPackageName()); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0); } else { return new Response(null, null, null, graphObject, true); } } else if (identifiers.getAndroidAdvertiserId() == null && identifiers.getAttributionId() == null) { throw new FacebookException("No attribution id available to send to server."); } else { if (!Utility.queryAppSettings(applicationId, false).supportsAttribution()) { throw new FacebookException("Install attribution has been disabled on the server."); } Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.commit(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }
Example 18
Source File: Settings.java From barterli_android with Apache License 2.0 | 4 votes |
static Response publishInstallAndWaitForResponse( final Context context, final String applicationId, final boolean isAutoPublish) { try { if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } String attributionId = Settings.getAttributionId(context.getContentResolver()); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId+"ping"; String jsonKey = applicationId+"json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); // prevent auto publish from occurring if we have an explicit call. if (!isAutoPublish) { setShouldAutoPublishInstall(false); } GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); Utility.setAppEventAttributionParameters(publishParams, attributionId, Utility.getHashedDeviceAndAppID(context, applicationId), !getLimitEventAndDataUsage(context)); publishParams.setProperty(AUTO_PUBLISH, isAutoPublish); publishParams.setProperty("application_package_name", context.getPackageName()); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0); } else { return new Response(null, null, graphObject, true); } } else if (attributionId == null) { throw new FacebookException("No attribution id returned from the Facebook application"); } else { if (!Utility.queryAppSettings(applicationId, false).supportsAttribution()) { throw new FacebookException("Install attribution has been disabled on the server."); } Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.commit(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }
Example 19
Source File: Settings.java From facebook-api-android-maven with Apache License 2.0 | 4 votes |
static Response publishInstallAndWaitForResponse( final Context context, final String applicationId, final boolean isAutoPublish) { try { if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } AttributionIdentifiers identifiers = AttributionIdentifiers.getAttributionIdentifiers(context); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId+"ping"; String jsonKey = applicationId+"json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); // prevent auto publish from occurring if we have an explicit call. if (!isAutoPublish) { setShouldAutoPublishInstall(false); } GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); Utility.setAppEventAttributionParameters(publishParams, identifiers, Utility.getHashedDeviceAndAppID(context, applicationId), getLimitEventAndDataUsage(context)); publishParams.setProperty(AUTO_PUBLISH, isAutoPublish); publishParams.setProperty("application_package_name", context.getPackageName()); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0); } else { return new Response(null, null, null, graphObject, true); } } else if (identifiers == null || (identifiers.getAndroidAdvertiserId() == null && identifiers.getAttributionId() == null)) { throw new FacebookException("No attribution id available to send to server."); } else { if (!Utility.queryAppSettings(applicationId, false).supportsAttribution()) { throw new FacebookException("Install attribution has been disabled on the server."); } Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.commit(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }
Example 20
Source File: Settings.java From platform-friends-android with BSD 2-Clause "Simplified" License | 4 votes |
static Response publishInstallAndWaitForResponse( final Context context, final String applicationId, final boolean isAutoPublish) { try { if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } String attributionId = Settings.getAttributionId(context.getContentResolver()); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId+"ping"; String jsonKey = applicationId+"json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); // prevent auto publish from occurring if we have an explicit call. if (!isAutoPublish) { setShouldAutoPublishInstall(false); } GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); Utility.setAppEventAttributionParameters(publishParams, attributionId, Utility.getHashedDeviceAndAppID(context, applicationId), !getLimitEventAndDataUsage(context)); publishParams.setProperty(AUTO_PUBLISH, isAutoPublish); publishParams.setProperty("application_package_name", context.getPackageName()); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0); } else { return new Response(null, null, graphObject, true); } } else if (attributionId == null) { throw new FacebookException("No attribution id returned from the Facebook application"); } else { if (!Utility.queryAppSettings(applicationId, false).supportsAttribution()) { throw new FacebookException("Install attribution has been disabled on the server."); } Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.commit(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }