-
Notifications
You must be signed in to change notification settings - Fork 10
Conversations Tutorial
In order to work with the Conversations SDK, please make sure you have met the minimum requirements defined on the Home Page.
For this tutorial, we'll create a simple Single View based application using Android Studio 1.5.1
-
From the Android Studio welcome screen click Start a new Android Studio project
Provide an Application name and then hit Next taking all the defaults until you are able to press Finish.
Now we are ready to set up our API and client ID and initialize the BVSDK.
- Create a new Java Class in your main app package by right clicking the package -> New -> Java Class and name it BVApplication. You will now make it a subclass of android.app.Application, override onCreate and initialize the SDK. The resulting code should look as follows although you will need to provide the client id, environment, Conversations key, and log level:
TIP: If you do not have a key yet and just want to get familiar with the SDK you can use a conversations key value of
kuy3zj9pr3n7i0wxajrzj04xo, a clientId ofapitestcustomer, and BazaarEnvironment.STAGING environment.
package com.example.bazaarvoice.conversationstutorial;
import android.app.Application;
import com.bazaarvoice.bvandroidsdk.BVLogLevel;
import com.bazaarvoice.bvandroidsdk.BVSDK;
import com.bazaarvoice.bvandroidsdk.BazaarEnvironment;
/**
* Created by Bazaarvoice on 1/18/16.
*/
public class BVApplication extends Application {
@Override
public void onCreate(){
super.onCreate();
// Builder used to initialize the Bazaarvoice SDKs
BVSDK bvsdk = new BVSDK.Builder(this)
.clientId(YOUR_CLIENT_ID)
.shopperAdvertisingEnvironment(BazaarEnvironment.PRODUCTION)
.apiKeyConversations(YOUR_CONVERSATIONS_KEY)
.logLevel(BVLogLevel.INFO)
.build();
}
}- Open **AndroidManifest.xml and set the name of the class for the application entry and request internet permission
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".BVApplication">
...- Build and run your app to make sure it is error free and loads "Hello World!".
At this point you should have the BVSDK installed and initialized, so we can now make an API call to the Conversations API.
-
Open up
MainActivity.java -
Make an API call.
In the
onCreatemethod make an API call to get some reviews and use an OnBazaarResponse callback to output the result to the console
BazaarRequest request = new BazaarRequest();
request.sendDisplayRequest(RequestType.REVIEWS, null, new OnBazaarResponse() {
@Override
public void onResponse(String url, JSONObject response) {
try {
Log.d("MainActivity", response.toString(1));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onException(String message, Throwable exception) {
//handle exception
}
});-
Finally, run the application and check the console for a successful API call.
In order the get more familiar with the Conversations module APIs, you should become familiar with the
BVGetandBVPostclasses which are used to construt all the Conversations API calls. All explore the Examples in theExamples/folder of the SDK from this repository.
© 2016 Bazaarvoice, Inc.
Use of this SDK is contingent on your agreement and conformance with Bazaarvoice's API Terms of Use. Additionally, you agree to store all data acquired by this SDK or Bazaarvoice’s API only within the storage of the individual application instance using the SDK or API. You also agree to use the data acquired by the SDK or API only within the context of the same individual application instance and only for purposes consistent with that application’s purpose. Except as otherwise noted, the Bazaarvoice iOS SDK licensed under the Apache License, Version 2.0.