Skip to content

Java

Tagging a User

This is a simple java example to update user's first name in StreetHawk for a particular "cuid" so that you can provide real-time triggered campaigns based on these "tags".

public static void tagInStreethawk() {
    String HOST_URL_FOR_TAGGING = "<Your API HOST>"; // API HOST is in the Dashboard "App Details"
    String APP_KEY = "<YOUR_APPS_APP_KEY>"; //APP_KEY should be your application's app_key registered with Streethawk
    String AUTH_TOKEN=""; // This can be found in the Dashboard "App Details"
    String cuid = "<CUID_OF_INSTALL>"; // cuid of the install to be tagged
    String FIRST_NAME = "<FIRST_NAME_OF_USER>"; // First name of user which will be updated in Streethawk

    HttpClient httpclient;
    HttpPost httppost;
    ArrayList<NameValuePair> postParameters;
    httpclient = HttpClientBuilder.create().build();
    httppost = new HttpPost(HOST_URL_FOR_TAGGING);
    httppost.setHeader("Accept", "application/json");
    httppost.setHeader("Content-type", "application/x-www-form-urlencoded");

    postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("app_key",APP_KEY));
    postParameters.add(new BasicNameValuePair("auth_token",AUTH_TOKEN));
    postParameters.add(new BasicNameValuePair("sh_cuid",cuid));
    postParameters.add(new BasicNameValuePair("key","sh_first_name"));
    postParameters.add(new BasicNameValuePair("string",FIRST_NAME));
    System.out.println(postParameters);
    try {
        httppost.setEntity(new UrlEncodedFormEntity(postParameters));
        HttpResponse response = httpclient.execute(httppost);
        System.out.println(response.getStatusLine());
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}