Forum Discussion

pbi_taken's avatar
pbi_taken
Helper I
1 year ago
Solved

Http requests in Fabric Notebook

Hi, I'm trying get my activites from the strava API in a Fabric notebook. I've followed all the instructions and it works fine. One issue I have is that I would like to automate getting data. What ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi pbi_taken,

    Thank you for reaching out in Microsoft Community Forum.

    Please follow below steps to Automating Strava API Data Access in Fabric Notebook

    1.The code from the Strava OAuth flow is only needed once to retrieve the initial access_token and refresh_token. After that, you should use the refresh_token to keep getting new access_tokens without requiring the code again.

    2.Replace grant_type = 'authorization_code' with grant_type = 'refresh_token' and call the token endpoint:

    response = requests.post(
    'https://www.strava.com/oauth/token',
    data={
    'client_id': client_id,
    'client_secret': client_secret,
    'grant_type': 'refresh_token',
    'refresh_token': refresh_token
    }
    )

    3.If you're getting 401 errors, check the access_token permissions. You must have activity:read_all scope granted during the initial authorization. If the token lacks required scopes, reauthorize manually with:

    https://www.strava.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http://localhost&response_type=code&scope=activity:read_all

    4.Add debugging for response.status_code and print response.json() to catch and understand errors:

    if response.status_code != 200:
    print("Error during token fetch:", response.status_code, response.json())

    If the issue still persists,In this scenario we suggest you to raise a support ticket here. so, that they can assit you in addressing the issue you are facing. please follow below link on how to raise a support ticket:

    How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn