How can I get the location of an object at each keyframe?
The reason your script was returning 0, 0, 0 is because you were printing the location of the object on the current frame.

Basically your code says:


  Print the location of the cube object the same number of times as there are number of keyframes.


So as mentioned by kilbee you need to set the scene frame to the frame that the keyframe is on in order to read the location of the object on that frame.

By combining your code with kilbee's:

import bpy

ob = bpy.context.object

for f in ob.animation_data.action.fcurves:
    for k in f.keyframe_points:
        fr = k.co[0]
        bpy.context.scene.frame_set(fr)
        pos=ob.location
        print(pos)


This way you only check frames with keyframes, as opposed to checking every frame.