New to swift - p2/Oauth2 is working fine, can't get SwaggerClientAPI "working."

135 views
Skip to first unread message

Tollman Owens

unread,
Jul 18, 2018, 10:23:10 PM7/18/18
to Strava API
Hi,

I am successfully authenticating from swift to Strava with p2/Oauth2 and requesting activities. I thought it would be nice to use the models out of the provided (thanks Strava) swagger spec. I've generated that code and added it to the project, and am absolutely unsuccessful in getting the SwaggerClientAPI to return anything other than errors. I'm getting 401's or 500's. I thought to add the oauth2.accessToken to the SwaggerClientAPI.customHeaders and maybe it would work, but does not.

        ActivitiesAPI.getLoggedInAthleteActivities { activities, error in
            debugPrint(activities as Any)
            debugPrint(error as Any)
        }

Everything is fine when 
        sessionManager.request("https://www.strava.com/api/v3/athlete/activities").validate().responseJSON { response in
            debugPrint(response)
        }

Clearly, the session manager from p2/Oauth2 is working.

I see in AlamofireImplementations.swift

open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
    required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) {
        super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody, headers: headers)
    }

    /**
     May be overridden by a subclass if you want to control the session
     configuration.
     */
    open func createSessionManager() -> Alamofire.SessionManager {
        let configuration = URLSessionConfiguration.default
        configuration.httpAdditionalHeaders = buildHeaders()
        return Alamofire.SessionManager(configuration: configuration)
    }

    // omitted
}

Should I be overriding the createSessionManager function to use the p2/oauth2 session manager?

What is everybody else doing in this situation?

Thanks!
T/O

Tollman Owens

unread,
Jul 19, 2018, 3:11:01 AM7/19/18
to Strava API
I seem to have got by the session issue, in probably not the best way. We can iterate...

Now I'm getting this formatting error, 

Optional(Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), "start_date"], debugDescription: "Date string does not match format expected by formatter.", underlyingError: nil)))

Is there obvious someplace I should be setting a format?
Reply all
Reply to author
Forward
0 new messages