Example usage for org.json JSONObject getString

List of usage examples for org.json JSONObject getString

Introduction

In this page you can find the example usage for org.json JSONObject getString.

Prototype

public String getString(String key) throws JSONException 

Source Link

Document

Get the string associated with a key.

Usage

From source file:org.b3log.solo.event.symphony.CommentSender.java

@Override
public void action(final Event<JSONObject> event) throws EventException {
    final JSONObject data = event.getData();
    LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
            new Object[] { event.getType(), data, ArticleSender.class.getName() });
    try {// ww  w.  j a v  a2s .c  o m
        final JSONObject originalComment = data.getJSONObject(Comment.COMMENT);

        final JSONObject preference = preferenceQueryService.getPreference();
        if (null == preference) {
            throw new EventException("Not found preference");
        }

        final String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase();
        if (blogHost.contains("localhost")) {
            LOGGER.log(Level.INFO,
                    "Blog Solo runs on local server, so should not send this comment[id={0}] to Symphony",
                    new Object[] { originalComment.getString(Keys.OBJECT_ID) });
            return;
        }

        final HTTPRequest httpRequest = new HTTPRequest();
        httpRequest.setURL(ADD_COMMENT_URL);
        httpRequest.setRequestMethod(HTTPRequestMethod.PUT);
        final JSONObject requestJSONObject = new JSONObject();
        final JSONObject comment = new JSONObject();
        comment.put("commentId", originalComment.optString(Keys.OBJECT_ID));
        comment.put("commentAuthorName", originalComment.getString(Comment.COMMENT_NAME));
        comment.put("commentAuthorEmail", originalComment.getString(Comment.COMMENT_EMAIL));
        comment.put(Comment.COMMENT_CONTENT, originalComment.getString(Comment.COMMENT_CONTENT));
        comment.put("articleId", originalComment.getString(Comment.COMMENT_ON_ID));

        requestJSONObject.put(Comment.COMMENT, comment);
        requestJSONObject.put("clientVersion", SoloServletListener.VERSION);
        requestJSONObject.put("clientRuntimeEnv", Latkes.getRuntimeEnv().name());
        requestJSONObject.put("clientName", "B3log Solo");
        requestJSONObject.put("clientHost", blogHost);
        requestJSONObject.put("clientAdminEmail", preference.optString(Preference.ADMIN_EMAIL));
        requestJSONObject.put("userB3Key", preference.optString(Preference.KEY_OF_SOLO));

        httpRequest.setPayload(requestJSONObject.toString().getBytes("UTF-8"));

        urlFetchService.fetchAsync(httpRequest);
    } catch (final Exception e) {
        LOGGER.log(Level.SEVERE, "Sends a comment to Symphony error: {0}", e.getMessage());
    }

    LOGGER.log(Level.FINER, "Sent a comment to Symphony");
}

From source file:com.github.koraktor.steamcondenser.community.AppNews.java

/**
 * Creates a new instance of an AppNews news item with the given data
 *
 * @param appId The unique Steam Application ID of the game (e.g.
 *        <code>440</code> for Team Fortress 2). See
 *        http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
 *        all application IDs//w  w  w  . j a v  a 2 s . c om
 * @param newsData The news data extracted from JSON
 * @throws WebApiException if the JSON data cannot be parsed
 */
private AppNews(int appId, JSONObject newsData) throws WebApiException {
    try {
        this.appId = appId;
        this.author = newsData.getString("author");
        this.contents = newsData.getString("contents").trim();
        this.date = new Date(newsData.getLong("date"));
        this.external = newsData.getBoolean("is_external_url");
        this.feedLabel = newsData.getString("feedlabel");
        this.feedName = newsData.getString("feedname");
        this.gid = newsData.getLong("gid");
        this.title = newsData.getString("title");
        this.url = newsData.getString("url");
    } catch (JSONException e) {
        throw new WebApiException("Could not parse JSON data.", e);
    }
}

From source file:de.dmxcontrol.executor.EntityExecutor.java

public static EntityExecutor Receive(JSONObject o) {
    EntityExecutor entity = null;//from   w  w  w .  jav  a2s.  c om
    try {
        if (o.getString("Type").equals(NetworkID)) {
            entity = new EntityExecutor(o.getInt("Number"), o.getString("Name"));
            entity.guid = o.getString("GUID");
            if (o.has("Value")) {
                entity.value = Float.parseFloat(o.getString("Value").replace(",", "."));
            }
            if (o.has("Flash")) {
                entity.flash = o.getBoolean("Flash");
            }
            if (o.has("Toggle")) {
                entity.toggle = o.getBoolean("Toggle");
            }
            if (o.has("FaderMode")) {
                entity.faderMode = o.getInt("FaderMode");
            }
        }
    } catch (Exception e) {
        Log.e("UDP Listener", e.getMessage());
        DMXControlApplication.SaveLog();
    }
    o = null;
    if (o == null) {
        ;
    }
    return entity;
}

From source file:com.abeo.tia.noordin.AddCaseStep2of4.java

public void dropdownBankDeveloperSolicitor() {

    RequestParams params = null;//from  w  w w.j  a  v  a  2  s .  c om
    params = new RequestParams();

    RestService.post(METHOD_PROPERTY_BDS_DROPDOWN, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("Property Activity GetDropdown Success Details ");
            try {
                // Create new list
                jsonlistBank = new ArrayList<HashMap<String, String>>();
                jsonlistDeveloper = new ArrayList<HashMap<String, String>>();
                jsonlistSolicitor = new ArrayList<HashMap<String, String>>();

                jsonResponse = new JSONObject(arg2);

                JSONArray jsonBank = jsonResponse.getJSONArray("Bank");
                for (int j = 0; j < jsonBank.length(); j++) {
                    JSONObject bank = jsonBank.getJSONObject(j);

                    id_b = bank.getString("BankCode").toString();
                    name_b = bank.getString("BankName").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> bankList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND JSON BANK LIST");
                    bankList.put("Id_T", id_b);
                    System.out.println(name);
                    bankList.put("Name_T", name_b);
                    System.out.println(name);
                    System.out.println(" END SEND JSON BANK LIST");

                    jsonlistBank.add(bankList);
                    System.out.println("JSON BANK LIST");
                    System.out.println(jsonlistProject);

                }

                // Spinner set Array Data in Drop down

                sAdapBANK = new SimpleAdapter(AddCaseStep2of4.this, jsonlistBank, R.layout.spinner_item,
                        new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name });

                spinnerpropertyLSTCHG_BANKNAME.setAdapter(sAdapBANK);

                for (int j = 0; j < jsonlistBank.size(); j++) {
                    if (jsonlistBank.get(j).get("Name_T").equals(bankDetailResponse)) {
                        spinnerpropertyLSTCHG_BANKNAME.setSelection(j);
                        break;
                    }
                }

                JSONArray jsonDeveloper = jsonResponse.getJSONArray("Developer");
                for (int j = 0; j < jsonDeveloper.length(); j++) {
                    JSONObject dev = jsonDeveloper.getJSONObject(j);
                    id = dev.getString("DevCode").toString();
                    name = dev.getString("DevName").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> devList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND JSON DEV LIST");
                    devList.put("Id_B", id);
                    System.out.println(name);
                    devList.put("Name_B", name);
                    System.out.println(name);
                    System.out.println(" END SEND JSON DEV LIST");

                    jsonlistDeveloper.add(devList);
                    System.out.println("JSON DEV LIST");
                    System.out.println(jsonlistDeveloper);

                }
                // Spinner set Array Data in Drop down

                sAdapDEV = new SimpleAdapter(AddCaseStep2of4.this, jsonlistDeveloper, R.layout.spinner_item,
                        new String[] { "Id_B", "Name_B" }, new int[] { R.id.Id, R.id.Name });

                spinnerpropertyDEVELOPER.setAdapter(sAdapDEV);

                for (int j = 0; j < jsonlistDeveloper.size(); j++) {
                    if (jsonlistDeveloper.get(j).get("Id_B").equals(developerCodeResponse)) {
                        spinnerpropertyDEVELOPER.setSelection(j);
                        break;
                    }
                }

                JSONArray jsonSolicitor = jsonResponse.getJSONArray("Solicitor");
                for (int j = 0; j < jsonSolicitor.length(); j++) {
                    JSONObject solic = jsonSolicitor.getJSONObject(j);
                    id = solic.getString("SoliCode").toString();
                    name = solic.getString("SoliName").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> solicList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND JSON SOLICITOR LIST");
                    solicList.put("Id_T", id);
                    System.out.println(name);
                    solicList.put("Name_T", name);
                    System.out.println(name);
                    System.out.println(" END SEND JSON SOLICITOR LIST");

                    jsonlistSolicitor.add(solicList);
                    System.out.println("JSON SOLICITOR LIST");
                    System.out.println(jsonlistSolicitor);
                }

                // Spinner set Array Data in Drop down
                sAdapSOLIC = new SimpleAdapter(AddCaseStep2of4.this, jsonlistSolicitor, R.layout.spinner_item,
                        new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name });

                spinnerpropertyDEVSOLICTOR.setAdapter(sAdapSOLIC);

                for (int j = 0; j < jsonlistSolicitor.size(); j++) {
                    if (jsonlistSolicitor.get(j).get("Id_T").equals(devSolictorCodeResponse)) {
                        spinnerpropertyDEVSOLICTOR.setSelection(j);
                        break;
                    }
                }

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            System.out.println(arg2);

        }

        @Override
        protected String parseResponse(String arg0, boolean arg1) throws Throwable {
            // Get Json response

            System.out.println("Property GetDropdown parse Response");
            System.out.println(arg0);
            return null;
        }

    });

}

From source file:com.abeo.tia.noordin.AddCaseStep2of4.java

public void setallvalues(Object data) throws JSONException {

    //JSONObject jObj =  new JSONObject(data.toString());
    JSONObject jObj = (JSONObject) data;
    //JSONObject jObj = arr.getJSONObject(0);

    System.out.println(jObj);/*  www. j a  v a  2  s  .co  m*/
    String compareValue = "some value";
    //int spinnerPosition = sAdapPROJ.

    spinnerpropertyPROJECT.setSelection(1);

    //titleValue.setText(jObj.getString("TITLETYPE"));
    Title.setText(jObj.getString("TITLENO"));

    LotType.setText(jObj.getString("LOTTYPE"));
    LotNo.setText(jObj.getString("LOTNO"));
    Knownas.setText(jObj.getString("FORMERLY_KNOWN_AS"));
    projectDetailResponse = "I";

    Pekan.setText(jObj.getString("BPM"));
    //Daerah.setText(jObj.getString("STATE"));
    Nageri.setText(jObj.getString("AREA"));
    LotArea.setText(jObj.getString("LOTAREA"));
    statevalue = jObj.getString("STATE");
    LastUpdate.setText(jObj.getString("LASTUPDATEDON"));
    //developerValue.setText(jObj.getString("DEVELOPER"));
    //developerValue_id.setText(jObj.getString("DVLPR_CODE"));
    //ProjectValue_id.setText(jObj.getString("PROJECT_CODE"));
    //ProjectValue.setText(jObj.getString("PROJECTNAME"));
    DevLicense.setText(jObj.getString("DEVLICNO"));
    //solicitorValue.setText(jObj.getString("DEVSOLICTOR"));
    SolicitorLoc.setText(jObj.getString("DVLPR_LOC"));
    //bankValue_id.setText(jObj.getString("LSTCHG_BANKCODE"));
    //bankValue.setText(jObj.getString("LSTCHG_BANKNAME"));
    Branch.setText(jObj.getString("LSTCHG_BRANCH"));
    PAName.setText(jObj.getString("LSTCHG_PANO"));
    PresentaionNo.setText(jObj.getString("LSTCHG_PRSTNO"));

    LSTCHG_PRSTLINK = jObj.getString("LSTCHG_PRSTLINK");
    TITLELINK = jObj.getString("TITLELINK");

    if (jObj.getString("PROPERTYCHARGED").equals("Y"))
        QryGroup13.setChecked(true);
    if (jObj.getString("PROPERTYCHARGED").equals("N"))
        QryGroup13.setChecked(false);
    PurchasePrice.setText(jObj.getString("PurchasePrice"));

}

From source file:com.util.httpAccount.java

public Account getAccountObject(String tel) {
    String telefono = tel.replace("-", "");
    System.out.println("OBTENER SOLO UN ARRAY DE CADENA JSON");
    //String myURL = "http://192.168.5.44/app_dev.php/cus/getaccount/50241109321.json";
    String myURL = "http://192.168.5.44/app_dev.php/cus/getaccount/" + telefono + ".json";
    System.out.println("Requested URL:" + myURL);
    StringBuilder sb = new StringBuilder();
    URLConnection urlConn = null;
    InputStreamReader in = null;/*  w  w  w .ja  v a  2  s  . c o  m*/
    Account account = new Account();
    try {
        URL url = new URL(myURL);
        urlConn = url.openConnection();
        if (urlConn != null) {
            urlConn.setReadTimeout(60 * 1000);
            if (urlConn != null && urlConn.getInputStream() != null) {
                in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset());

                BufferedReader bufferedReader = new BufferedReader(in);
                if (bufferedReader != null) {
                    int cp;
                    while ((cp = bufferedReader.read()) != -1) {
                        sb.append((char) cp);
                    }
                    bufferedReader.close();
                }
            }

            String jsonResult = sb.toString();
            // System.out.println(sb.toString());
            //System.out.println("\n\n--------------------OBTENEMOS OBJETO JSON NATIVO DE LA PAGINA, USAMOS EL ARRAY DATA---------------------------\n\n");
            JSONObject objJason = new JSONObject(jsonResult);
            JSONArray dataJson = new JSONArray();
            dataJson = objJason.getJSONArray("data");

            //System.out.println("objeto normal 1 "+dataJson.toString());
            //
            //
            // System.out.println("\n\n--------------------CREAMOS UN STRING JSON2 REEMPLAZANDO LOS CORCHETES QUE DAN ERROR---------------------------\n\n");
            String jsonString2 = dataJson.toString();
            String temp = dataJson.toString();
            temp = jsonString2.replace("[", "");
            jsonString2 = temp.replace("]", "");
            // System.out.println("new json string"+jsonString2);

            JSONObject objJson2 = new JSONObject(jsonString2);
            // System.out.println("el objeto simple json es " + objJson2.toString());

            // System.out.println("\n\n--------------------CREAMOS UN OBJETO JSON CON EL ARRAR ACCOUN---------------------------\n\n");
            String account1 = objJson2.optString("account");
            // System.out.println(account1);
            JSONObject objJson3 = new JSONObject(account1);
            //   System.out.println("el ULTIMO OBJETO SIMPLE ES  " + objJson3.toString());
            //   System.out.println("\n\n--------------------EMPEZAMOS A RECIBIR LOS PARAMETROS QUE HAY EN EL OBJETO JSON---------------------------\n\n");
            String firstName = objJson3.getString("first_name");
            System.out.println(firstName);
            System.out.println(objJson3.get("language_id"));
            //  System.out.println("\n\n--------------------TRATAMOS DE PASAR TODO EL ACCOUNT A OBJETO JAVA---------------------------\n\n");
            Gson gson = new Gson();
            account = gson.fromJson(objJson3.toString(), Account.class);
            //System.out.println(account.getFirst_name());
            // System.out.println(account.getCreation());
            account.setLanguaje_id(objJson3.get("language_id").toString());
            account.setId(objJson3.get("id").toString());
            account.setBalance(objJson3.get("balance").toString());
            System.out.println("el id del account es " + account.getId());

        } else {
            System.out.print("no se pudo conectar con el servidor");
            account = null;
        }

        in.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Exception while calling URL:" + myURL, e);
    }

    return account;
}

From source file:com.skalski.raspberrycontrol.Activity_RemoteControl.java

Handler getClientHandler() {

    return new Handler() {
        @Override//from ww w  . j  a va  2 s.  co  m
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            JSONObject root;
            Log.i(LOGTAG, LOGPREFIX + "new message received from server");

            try {

                root = new JSONObject(msg.obj.toString());

                if (root.has(TAG_ERROR)) {
                    String err = getResources().getString(R.string.com_msg_3) + root.getString(TAG_ERROR);
                    Log.e(LOGTAG, LOGPREFIX + root.getString(TAG_ERROR));
                    toast_connection_error(err);
                }

            } catch (Exception ex) {
                Log.e(LOGTAG, LOGPREFIX + "received invalid JSON object");
                toast_connection_error(getResources().getString(R.string.error_msg_2));
            }
        }
    };
}

From source file:com.goliathonline.android.kegbot.io.RemoteDrinksHandler.java

/** {@inheritDoc} */
@Override//from ww w. j  av a2 s.  com
public ArrayList<ContentProviderOperation> parse(JSONObject parser, ContentResolver resolver)
        throws JSONException, IOException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();

    // Walk document, parsing any incoming entries
    int drink_id = 0;
    JSONObject result = parser.getJSONObject("result");
    JSONArray drinks = result.getJSONArray("drinks");
    JSONObject drink;
    for (int i = 0; i < drinks.length(); i++) {
        if (drink_id == 0) { // && ENTRY.equals(parser.getName()
            // Process single spreadsheet row at a time
            drink = drinks.getJSONObject(i);
            final String drinkId = sanitizeId(drink.getString("id"));
            final Uri drinkUri = Drinks.buildDrinkUri(drinkId);

            // Check for existing details, only update when changed
            final ContentValues values = queryDrinkDetails(drinkUri, resolver);
            final long localUpdated = values.getAsLong(SyncColumns.UPDATED);
            final long serverUpdated = 500; //entry.getUpdated();
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "found drink " + drinkId);
                Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated);
            }
            if (localUpdated != KegbotContract.UPDATED_NEVER)
                continue;

            final Uri drinkKegUri = Drinks.buildKegUri(drinkId);
            final Uri drinkUserUri = Drinks.buildUserUri(drinkId);

            // Clear any existing values for this session, treating the
            // incoming details as authoritative.
            batch.add(ContentProviderOperation.newDelete(drinkUri).build());
            batch.add(ContentProviderOperation.newDelete(drinkKegUri).build());

            final ContentProviderOperation.Builder builder = ContentProviderOperation
                    .newInsert(Drinks.CONTENT_URI);

            builder.withValue(SyncColumns.UPDATED, serverUpdated);
            builder.withValue(Drinks.DRINK_ID, drinkId);

            // Inherit starred value from previous row
            if (values.containsKey(Drinks.DRINK_STARRED)) {
                builder.withValue(Drinks.DRINK_STARRED, values.getAsInteger(Drinks.DRINK_STARRED));
            }

            if (drink.has("session_id"))
                builder.withValue(Drinks.SESSION_ID, drink.getInt("session_id"));
            if (drink.has("status"))
                builder.withValue(Drinks.STATUS, drink.getString("status"));
            if (drink.has("user_id"))
                builder.withValue(Drinks.USER_ID, drink.getString("user_id"));
            if (drink.has("keg_id"))
                builder.withValue(Drinks.KEG_ID, drink.getInt("keg_id"));
            if (drink.has("volume_ml"))
                builder.withValue(Drinks.VOLUME, drink.getDouble("volume_ml"));
            if (drink.has("pour_time"))
                builder.withValue(Drinks.POUR_TIME, drink.getString("pour_time"));

            // Normal session details ready, write to provider
            batch.add(builder.build());

            // Assign kegs
            final int kegId = drink.getInt("keg_id");
            batch.add(ContentProviderOperation.newInsert(drinkKegUri).withValue(DrinksKeg.DRINK_ID, drinkId)
                    .withValue(DrinksKeg.KEG_ID, kegId).build());

            // Assign users
            if (drink.has("user_id")) {
                final String userId = drink.getString("user_id");
                batch.add(ContentProviderOperation.newInsert(drinkUserUri)
                        .withValue(DrinksUser.DRINK_ID, drinkId).withValue(DrinksUser.USER_ID, userId).build());
            }
        }
    }

    return batch;
}

From source file:io.teak.sdk.Teak.java

/**************************************************************************/

@SuppressWarnings("unused")
private static void openIABPurchaseSucceeded(String json) {
    try {/*w w  w.j  av  a2s. c  o m*/
        JSONObject purchase = new JSONObject(json);
        if (Teak.isDebug) {
            Log.d(LOG_TAG, "OpenIAB purchase succeeded: " + purchase.toString(2));
        }

        if (Teak.appStore != null && Teak.appStore.ignorePluginPurchaseEvents()) {
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "OpenIAB callback ignored, store purchase reporting is auto-magical.");
            }
        } else {
            JSONObject originalJson = new JSONObject(purchase.getString("originalJson"));
            purchaseSucceeded(originalJson);
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, Log.getStackTraceString(e));
        Teak.sdkRaven.reportException(e);
    }
}

From source file:io.teak.sdk.Teak.java

static void purchaseSucceeded(final JSONObject purchaseData) {
    Teak.asyncExecutor.submit(new Runnable() {
        public void run() {
            try {
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Purchase succeeded: " + purchaseData.toString(2));
                }//from ww w  .  j  a  va 2 s  .c  o  m

                final HashMap<String, Object> payload = new HashMap<>();

                if (Teak.appConfiguration.installerPackage == null) {
                    Log.e(LOG_TAG, "Purchase succeded from unknown app store.");
                } else if (Teak.appConfiguration.installerPackage.equals("com.amazon.venezia")) {
                    JSONObject receipt = purchaseData.getJSONObject("receipt");
                    JSONObject userData = purchaseData.getJSONObject("userData");

                    payload.put("purchase_token", receipt.get("receiptId"));
                    payload.put("purchase_time_string", receipt.get("purchaseDate"));
                    payload.put("product_id", receipt.get("sku"));
                    payload.put("store_user_id", userData.get("userId"));
                    payload.put("store_marketplace", userData.get("marketplace"));

                    Log.d(LOG_TAG, "Purchase of " + receipt.get("sku") + " detected.");
                } else {
                    payload.put("purchase_token", purchaseData.get("purchaseToken"));
                    payload.put("purchase_time", purchaseData.get("purchaseTime"));
                    payload.put("product_id", purchaseData.get("productId"));
                    if (purchaseData.has("orderId")) {
                        payload.put("order_id", purchaseData.get("orderId"));
                    }

                    Log.d(LOG_TAG, "Purchase of " + purchaseData.get("productId") + " detected.");
                }

                if (Teak.appStore != null) {
                    JSONObject skuDetails = Teak.appStore.querySkuDetails((String) payload.get("product_id"));
                    if (skuDetails != null) {
                        if (skuDetails.has("price_amount_micros")) {
                            payload.put("price_currency_code", skuDetails.getString("price_currency_code"));
                            payload.put("price_amount_micros", skuDetails.getString("price_amount_micros"));
                        } else if (skuDetails.has("price_string")) {
                            payload.put("price_string", skuDetails.getString("price_string"));
                        }
                    }
                }

                Session.whenUserIdIsReadyRun(new Session.SessionRunnable() {
                    @Override
                    public void run(Session session) {
                        new Request("/me/purchase", payload, session).run();
                    }
                });
            } catch (Exception e) {
                Log.e(LOG_TAG, "Error reporting purchase: " + Log.getStackTraceString(e));
                Teak.sdkRaven.reportException(e);
            }
        }
    });
}