Change $product->getAttribute() to $product->getAttributes():
/**
* Retrieve product attributes
* if $groupId is null - retrieve all product attributes
*
* @param int $groupId Retrieve attributes of the specified group
* @param bool $skipSuper Not used
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getAttributes($groupId = null, $skipSuper = false)
{
$productAttributes = $this->getTypeInstance()->getEditableAttributes($this);
if ($groupId) {
$attributes = [];
foreach ($productAttributes as $attribute) {
if ($attribute->isInGroup($this->getAttributeSetId(), $groupId)) {
$attributes[] = $attribute;
}
}
} else {
$attributes = $productAttributes;
}
return $attributes;
}
Now you would be able to loop through the attributes and have access to the attribute object. You are able to use $attribute->getCode() to get the code.