Fit timeline to first/last frame via python
You have to set a custom context, because the operator requires a specific context in which it can be executed. Otherwise the check implemented in its .poll() function will return false and execution fails.

You can accomplish this by iterating through the areas to find the timeline (which is now called DOPESHEET_EDITOR instead of TIMELINE in Blender 2.8). Then you also need the correct region with the type WINDOW. Once you have both you can create a custom context. 

This script requires that you have the timeline open as an area somewhere in the UI.

import bpy

scene = bpy.context.scene
scene.frame_start = 50
scene.frame_end = 100

for area in bpy.context.screen.areas:
    if area.type == 'DOPESHEET_EDITOR':
        for region in area.regions:
            if region.type == 'WINDOW':
                ctx = bpy.context.copy()
                ctx['area'] = area
                ctx['region'] = region
                bpy.ops.action.view_all(ctx)
                break
        break