Magento getConfigurableAttributesAsArray导致致命错误

I am trying to write a script that creates configurable products. Ive been using this as a guide: http://inchoo.net/magento/programmatically-create-a-configurable-magento-product/

When I get to this line:

$configurableAttributesData = $configProduct->getTypeInstance()->getConfigurableAttributesAsArray();

The script crashes and kicks out this error:

Fatal error:  Call to a member function getId() on a non-object in /home/buyfrom/public_html/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php on line 283

Following a comment on this page, I changed that line to the following:

$possibleAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);

But I am still getting this error. Can anyone suggest how to fix this?

Make sure that attribute set (eg. default) which you are choosing is having at least one configurable attribute (example: 'color' or 'size').