Authorization error from SWAGGER

691 views
Skip to first unread message

Druti Gangwar

unread,
Dec 22, 2021, 5:21:11 AM12/22/21
to Strava API
Hello!

I am trying to retrieve segment data from STRAVA using an API. But when I authorize my client ID and secret from SWAGGER. It is giving me an authorization error. If anyone has faced similar issues and has a way out, I would really appreciate your help.

Regards,
Druti

kingo...@gmail.com

unread,
Dec 22, 2021, 5:43:21 AM12/22/21
to Strava API
Please, when reporting a technical problem you must provide your exact error message otherwise people that want to help have to guess, which is a waste of everyone's time. And if you search on here for (or part of) that error message you may even find the answer to your problem.

My guess is that your access token does not have the required scope for the data you want. You can read about scopes in the Strava documentation at https://developers.strava.com/docs/authentication/#detailsaboutrequestingaccess

Good luck,
Nick

Druti Gangwar

unread,
Dec 23, 2021, 5:11:06 AM12/23/21
to Strava API
Thank you @Nick for constructive feedback on how to report a technical problem. I am not a programmer/coder/computer science expert hence I do not know how to report coding-related errors. This is my first time working with the API. 

Anyways, I had already gone through the documentation in detail and followed the procedure. I used "read" as my scope. I have carried out all steps multiple times, however, the error doesn't seem to resolve. I will try a couple of times more to see if something changed today.

Still, if someone could extend their patience and time in helping an amateur like me, I would really appreciate it.  

kingo...@gmail.com

unread,
Dec 23, 2021, 9:45:26 AM12/23/21
to Strava API
Great, so we can assume this is a public segment you are trying to access. 

Please provide the exact api request you are doing (change the auth token) and the exact error response you are getting. 

Luis Lopez

unread,
Dec 31, 2021, 10:43:41 PM12/31/21
to Strava API
you can directly test the request, this example worked for me, just put in your own access_token.
https://www.strava.com/api/v3/segments/825967?before=1641081599&page=1&per_page=200&access_token=xxxxxxxxx

Druti Gangwar

unread,
Jan 1, 2022, 1:19:35 PM1/1/22
to Strava API
@Nick, I received an error while using SWAGGER. I inserted the lat longs in "segment explore" and then inserted client id and secret for the option selected "read" data in the authorize dialog box.

@Luis I changed the auth token in your link but I am receiving your information (I guessed it from details like Luis Lopez, F, Australia). Can you suggest a way to change the lat longs of the segments data?That way I can use it for my study area.

kingo...@gmail.com

unread,
Jan 1, 2022, 2:18:01 PM1/1/22
to Strava API
This is the third time I have asked - provide the exact response you got! Swagger shows you this. I'm not sure how you are getting an auth error, it works fine for me. Are you sure you are using the correct client ID and secret values?
Message has been deleted

Luis Lopez

unread,
Jan 2, 2022, 5:00:11 PM1/2/22
to Strava API
Hi, the segment is public, the data you see in json it has latitude & longitude start & end with the in between points are encoded polyline.
in regards to segment data each user can only see their results as I have pasted my array data.

    [start_latitude] => -37.927366951481 [start_longitude] => 144.63511453941 [end_latitude] => -37.920383736491 [end_longitude] => 144.65565430932

the actual latitude & longitude is encoded:
[polyline] => `unfFm`xqZuDyOq@cCm@cCaCuK{AeG}FyVaA}EoIw\oF}T

the encoded polyline also has to be checked for backslashes see  $encodedPointsLiteral = str_replace('\\',"\\\\",$encodedPoints);



finally using google maps api   var latlng_coords = google.maps.geometry.encoding.decodePath(js_polyline);

this is an example of what I have done, the altitude data is coming from google api and not the segment also extra latlng have been inserted to analyse the elevation  
Untitled.png
the segment
-37.926460 , 144.637800
-37.926210 , 144.638460
-37.925980 , 144.639120
-37.925330 , 144.641150
-37.924870 , 144.642460
-37.923600 , 144.646270
-37.923270 , 144.647380
-37.921590 , 144.652140
Untitled1.png
Array ( [id] => 825967 [resource_state] => 3 [name] => Werribee Main Rd to Fed Trail Sprint [activity_type] => Ride [distance] => 1968.05 [average_grade] => 0.1 [maximum_grade] => 1 [elevation_high] => 3.6 [elevation_low] => 1.6 [start_latlng] => Array ( [0] => -37.927366951481 [1] => 144.63511453941 ) [end_latlng] => Array ( [0] => -37.920383736491 [1] => 144.65565430932 ) [elevation_profile] => https://d3o5xota0a1fcr.cloudfront.net/v6/charts/QVVWKZ5LLAFSZ6CW3KCIWKK5JGANWMJ53QPELRQ6I6G74YGJB5GMQ33ZRHUKKCD4KX4JQT3YEPNATGXGSYWQ==== [start_latitude] => -37.927366951481 [start_longitude] => 144.63511453941 [end_latitude] => -37.920383736491 [end_longitude] => 144.65565430932 [climb_category] => 0 [city] => Cocoroc [state] => VIC [country] => Australia [private] => [hazardous] => [starred] => [created_at] => 2011-11-14T03:53:14Z [updated_at] => 2021-05-15T02:11:41Z [total_elevation_gain] => 2 [map] => Array ( [id] => s825967 [polyline] => `unfFm`xqZuDyOq@cCm@cCaCuK{AeG}FyVaA}EoIw\oF}T [resource_state] => 3 ) [effort_count] => 9869 [athlete_count] => 1063 [star_count] => 3 [athlete_segment_stats] => Array ( [pr_elapsed_time] => 135 [pr_date] => 2016-09-03 [pr_activity_id] => 698406916 [effort_count] => 516 ) [xoms] => Array ( [kom] => 2:10 [qom] => 2:40 [destination] => Array ( [href] => strava://segments/825967/leaderboard [type] => overall [name] => All-Time ) ) [local_legend] => Array ( [athlete_id] => 412790 [title] => Luis Lopez🏊🏼🚴🏻🏃🏽 [profile] => https://dgalywyr863hv.cloudfront.net/pictures/athletes/412790/2005616/1/large.jpg [effort_description] => 19 efforts in the last 90 days [effort_count] => 19 [effort_counts] => Array ( [overall] => 19 efforts [female] => 2 efforts ) [destination] => strava://segments/825967/local_legend?categories%5B%5D=overall ) )

Druti Gangwar

unread,
Jan 3, 2022, 5:10:35 AM1/3/22
to Strava API
@Nick I am using the Client ID and Secret I generated using my STRAVA Profile. I have attached the image of the error below. I don't know if it helps you in understanding my problem or not, but I do not have a better way of explaining it. 

Auth_Error_Druti.PNG

Luca Novali

unread,
Jan 4, 2022, 12:04:36 AM1/4/22
to Strava API
I think I have the same error.
I click on 'authorize' button in right-top corner and I use my client-id and client-secret, but I get this json
{"message":"Bad Request","errors":[{"resource":"Authorize","field":"scope","code":"invalid"}]}

Ben Coomes

unread,
Jan 4, 2022, 9:23:59 PM1/4/22
to Strava API
Druti, that is an odd error! In all the errors I have seen from the swagger playground, a new tab is opened which displays the result of authorization. If you open a developer console (Ctrl + Shift + J in Chrome) and then click authorize, are there any errors displayed in the Console or Network tabs? One possibility that I haven't seen mentioned here is that in order to use the Swagger playground, you must set the Authorization Callback Domain in the settings for your API application to 'strava.com'. Otherwise you will see an error indicating a bad redirect url. The error {"message":"Bad Request","errors":[{"resource":"Authorize","field":"scope","code":"invalid"}]} most likely indicates that you have not selected any scopes from the checklist.    Another thing to be very careful of is that when you are copying the client id and secret you do not include any spaces before or after the values.
Reply all
Reply to author
Forward
0 new messages