I am generating static images for polylines which is fetched from strava api. Now the issue is for some polylines the url is working fine but for others is shows the following error:
{
"message": "Not Authorized",
"error_detail": "Direct access not allowed"
}
uticDwwgmMBI@UF_@BC\I\FNARFFVBx@IbA@h@AFKDi@Dg@@KAEEGeAFsAHs@^KL?d@FRNDF@
@Eb@@
@Ct@EPWJG?MBi@BK?ECEOAiAHuAB]DId@EVBN?F@JJBF@d@?p@ElACJSJWDi@@ICMWAa@F_CF[l@Ef@DPTHl@Gr@CfA]
uticDwwgmMBI@UF_@BC\I\FNARFFVBx@IbA@h@AFKDi@Dg@@KAEEGeAFsAHs@^KL?d@FRNDF@
@Eb@@
@Ct@EPWJG?MBi@BK?ECEOAiAHuAB]DId@EVBN?F@JJBF@d@?p@ElACJSJWDi@@ICMWAa@F_CF[l@Ef@DPTHl@Gr@CfA]Rw@FMCKWEW?oAFcAFUFAZ?LELDX?LP@HBl@A\CJ@XCNA@CLUHu@DM?KCEYCkANsBBAT@A?HCr@BFLDBDJBX?VIpBCFWJ_AFIAGQASGy@PwBj@ITDNAX\@FA
BEV@^AHWNcAFGACCG[Eq@B[AUJ{ADALB`A@DBBNJ@FL?NIrA@DEVBN?ZIDGCq@F[AGGMq@Ai@LsBDCZCp@BHFDNB?B@@TAz@@VCR?f@AHKH[BABs@OII
The problem is ? (question mark) in the polyline which completely changes the url and hence the authentication token is not recognised so that the error is coming.
So what we need to do is to encode the polyline and then attach it with the complete url. Here is the code sample I am sharing:
import java.net.URLEncoder
val encodedPolyline = URLEncoder.encode(polyline)