Batching Support

64 views
Skip to first unread message

Matt

unread,
Sep 3, 2015, 7:34:56 PM9/3/15
to Google Analytics Management API
Today we updated the API to now support batched requests; In addition we have added special support for the User Permissions API. Batched User Permissions requests will see significant performance gains and reduced quota usage.

Chris Harrington

unread,
Sep 7, 2015, 9:49:32 PM9/7/15
to Google Analytics Management API
Any chance you could post a Java or .Net sample? All I see is Python
https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtUserPermissions#batching

Chris Harrington

unread,
Sep 7, 2015, 10:12:46 PM9/7/15
to Google Analytics Management API
Just found this example
https://developers.google.com/api-client-library/dotnet/guide/batch
But is very incomplete. Anyone got a functional sample?


On Thursday, September 3, 2015 at 7:34:56 PM UTC-4, Matt wrote:

Duncan Mckie

unread,
Oct 12, 2015, 9:53:34 AM10/12/15
to Google Analytics Management API
Hi Chris,

Just started playing around with this - took me a while to figure out the callback functionality (there are no examples using the <Void> type that seems to be required in the analytics library) but got there in the end.

Don't have time to pull together a full working example, but here's a quick overview of the steps involved:


// Required libraries
import com.google.api.client.googleapis.batch.BatchRequest;
import com.google.api.client.googleapis.batch.json.JsonBatchCallback;
import com.google.api.client.googleapis.json.GoogleJsonError;

// 1. Define callback function with actions to take on success & fail
   
private JsonBatchCallback<Void> setCallback(final String successMessage){

       
JsonBatchCallback<Void> callback = new JsonBatchCallback<Void>(){

           
@Override
           
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders)
                   
throws IOException {
               
System.out.println(e.getMessage());                
           
}

           
public void onSuccess(Void t, HttpHeaders responseHeaders)
                   
throws IOException {
               
System.out.println(successMessage);

           
}
       
};

       
return callback;
   
}


// 2. Initialise batch
BatchRequest batchRequest = analytics.batch();

// 3. Define action to take
analytics
.management().profileUserLinks().delete(accountId, webPropertyId, profileId, linkId)
// 4. Add to batch using queue(BatchRequest, JsonBatchCallback<Void>)
               
.queue(batchRequest, setCallback(userEmail + " deleted from profile ID " + profileId));

// 5. Run batch
batch
.execute();


Hope that helps.

Cheers,

Duncan
Reply all
Reply to author
Forward
0 new messages