Adjusting code sample to the new api 

I've tried to use and discovered that the api is changed.
Just adjusting the sample.