Forum Discussion
Http requests in Fabric Notebook
- Anonymous1 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:
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
Hi pbi_taken,
Thank you for reaching out in Microsoft Community Forum.
You do not need the original code again once you've received the refresh_token from the first manual authorization.
Please use the below steps to automate;
1.Use the refresh_token to get a new access_token:
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
}
)
2.Use only the access_token from that response to call Strava’s API:
headers = {'Authorization': f'Bearer {access_token}'}
requests.get('https://www.strava.com/api/v3/athlete/activities', headers=headers)
Please continue using Microsoft community forum.
If you found this post helpful, please consider marking it as "Accept as Solution" and give it a 'Kudos'. if it was helpful. help other members find it more easily.
Regards,
Pavan.
I really appreciate your help, but I still can't see a way around this..
according to strava documentation you need the code: Strava Developers.
trying what you suggested just results for me in a <Response [401]>..
Hmm really wish someone else has done this successfully in the past..
- Anonymous1 year agoNot applicable
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:
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