1

我正在尝试通过我的应用程序将我的锻炼上传到 strava 并且当我发送我的请求时它返回错误 400 并且这个:

(字符串?)$R0 = "{\"message\":\"Bad Request\",\"errors\":[{\"resource\":\"Upload\",\"field\":\"文件\",\"代码\":\"不是文件\"}]}"

我能够毫无问题地将我的应用程序连接到 strava。这是我到目前为止所做的:

func saveWorkout(_ workout: FirebaseWorkout, completion: @escaping (_ success: Bool, _ error: Error?) -> Void) {
    let opts: [String: Any?] = [
        "file": nil,
        "name": workout.name
        "description": nil,
        "trainer": false,
        "commute": false,
        "dataType": ".gpx",
        "externalId": workout.key
    ]
    if self.isAuthorized && userSettings.membership.hasFullAccess {
        workoutLib().analyticsEvent(kEventCategoryThirdParty, eventAction: "SAVE_WORKOUT", eventLabel: ThirdPartyApplication.strava.rawValue, eventValue: 1)
        workoutLib().debugLog("Strava: Save Workout")
        self.refreshTokenIfNeeded {
            _ = self.oauthswift.client.post("https://www.strava.com/api/v3/uploads", parameters: opts as OAuthSwift.Parameters, success: { (_) in
                workoutLib().debugLog("Strava: Save Workout Success")
                completion(true, nil)
            }) { (error) in
                workoutLib().debugLog("Strava: Save Workout \(error.localizedDescription)")
                completion(false, error)
            }
        }
    } else {
        completion(false, nil)
    }
}
4

1 回答 1

0

在 Strava API 文档 ( https://developers.strava.com/docs/uploads/ ) 中,该file字段是必需的,看起来您已将其设置为nil. 这可能就是它返回的not a file原因,因为没有文件通过。

于 2019-05-14T21:19:54.470 回答