mpclarkson / StravaSwift

A Swift wrapper for the Strava API v3
MIT License
102 stars 45 forks source link

How to upload .fit file to Strava ?? #12

Open jvashisht opened 6 years ago

frogg commented 5 years ago

I am also running into quite some issues when I attempt to upload a new activity to Strava.

For now I don't even want to include a file, I just want to create a new activity (e.g. running 5km). So far, I always get a 400 (Bad Request) response from Strava.

AnshulIronNetwork commented 5 years ago

@frogg Are you able to create a new activity? If yes, can you please share your code. As I am also trying to create a new activity but got errors.

frogg commented 5 years ago

I didn't check about the .fit file itself yet but I am able to contribute basic session info to starve. Example: https://www.strava.com/activities/1999653605

Ended up using this lib instead: https://github.com/SweetzpotAS/StravaZpot-Swift

See my PR here how to update it: https://github.com/SweetzpotAS/StravaZpot-Swift/pull/5

AnshulIronNetwork commented 5 years ago

Thanks for your reply. I have created an activity using alamofire by hitting the url and passing the parameters.

Can you please help me in the authorization callback domain because strava don't let anyone add the custom url like myapp:// (This field must be a domain, no slashes or path). But the safari needs an url scheme with colon, slashes to open the app on return from the authorization.

When I have checked the code of this example, I come to know that the given redirect uri also contains ://. So how can I register my application redirect uri ?

mjunkmyjunk commented 3 years ago

@AnshulIronNetwork I can't help on the upload but https://stackoverflow.com/a/65092728/14414215 this is how I managed to get redirectUri to work.

could you share how you created the activity? I am having trouble on the syntax to call for the upload. (There isn't an example in the readme.md or the example app)

@frogg I checked out StravaZpot but the syntax is a little bit hard for me and there wasn't an example project for me to refer to within it. You mentioned you managed to contribute a basic session. Could you share how you called the Instance?

Thanks

frogg commented 3 years ago

@frogg I checked out StravaZpot but the syntax is a little bit hard for me and there wasn't an example project for me to refer to within it. You mentioned you managed to contribute a basic session. Could you share how you called the Instance?

Use my fork of StravaZpot instead, the original repo doesn't seem to get any recent updates (indeed it has been archived by the author): https://github.com/frogg/StravaZpot-Swift

mjunkmyjunk commented 3 years ago

@frogg Thank for your repo link. I read thru the original repo and truth be told, I'm a bit stumped as to how to integrate it into my project. In fact, I don't even know where to start. (Newbie)

in fact, it says this in bold -> you are responsible for calling this code in a suitable thread, outside the UI thread. and I'm not even sure how to begin.

Would appreciate any help or an example project like what StravaSwift offers.

frogg commented 3 years ago

@frogg Thank for your repo link. I read thru the original repo and truth be told, I'm a bit stumped as to how to integrate it into my project. In fact, I don't even know where to start. (Newbie)

in fact, it says this in bold -> you are responsible for calling this code in a suitable thread, outside the UI thread. and I'm not even sure how to begin.

Would appreciate any help or an example project like what StravaSwift offers.

I‘d recommend looking into the documentation of dispatch queues: https://developer.apple.com/documentation/dispatch/dispatchqueue

The use for this is pretty simple:

DispatchQueue.global(qos: .background).async {
// make calls to the Strava API, they are now on a background thread
}

and then to upload a GPX file:

let gpxFileUrl = session.generateGPXFile()
let uploadAPI = UploadAPI(client: client)
let fileUpload = uploadAPI.upload(file : gpxFileUrl,
                                  withFilename : gpxFileUrl.lastPathComponent,
                                  withDataType : .gpx,
                                  withActivityType : .rockClimbing,
                                  withName : "\(ClimbingBusinessLogic.title(forClimbingType: session.climbingType)) Session",
                                  withDescription : "\(session.sessionDescription())\n\nTracked with Redpoint, https://redpoint-app.com",
                                  isPrivate : false,
                                  hasTrainer : false,
                                  isCommute : false,
                                  withExternalID : session.uuid.uuidString)
mjunkmyjunk commented 3 years ago

@frogg I'll read up on the DispatchQueue. I'm still wrapping my head around the auhenticationController and where to put it. In codes I've seen, looks like simplest would be to put it into appDelegate.swift and create it like a singleton (similar to StravaSwift) and then use the shared instance everywhere else?

Again thanks. I'll bang my head on the wall a few more days and see if I can get anywhere.