Kodeco Forums

Alamofire Tutorial: Getting Started

Take your first steps into Alamofire, the de facto networking library on iOS powering thousands of apps, by using the Imagga APIs to upload and analyze user photos.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/35-alamofire-tutorial-getting-started

Hi, I tried the finished project, but it shows an error. I already copy and prepare the authenticationToken. Here’s the error:

Error while uploading file: Optional(Alamofire.AFError.responseValidationFailed(Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(403)))

How can I fix? Thank you.

I made some changes for a Decodable version of your Tutorial here…

1 Like

@ron.kliffer Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi

This usually means there’s a problem with your authentication key. Can you double check and verify it?

Hi there,

Could you please explain why you are using enum for Constraints? Should we use struct for Constraints?

Cheers,
Charles

Hi
I’m not sure I understand the question. Where dod you see a use of enum for constraints?

I read the following code in ImaggaRouter.swift
public enum ImaggaRouter: URLRequestConvertible {
// 1
enum Constants {
static let baseURLPath = “http://api.imagga.com/v1
static let authenticationToken = “Basic xxx”
}

Oh ok, you meant Constants, not Constraints.

The reason I declare them as an enum is because an enum with no cases can’t be instantiated, whereas a struct can be, so using an enum helps avoid this kind of mistake.

Sorry about the typo. I understand now.
Thank you a lot! @ron.kliffer.

Hello everyone,

First of all, I would like to thank @ron.kliffer for the awesome tutorial!

Imagga’s API v1 will be stopped by the end of November 2018. There is a new API v2 interface which can be used, however, the API interface and the output result are both different.

To make the above tutorial work with API v2, I have reworked the two main files which you can find here:
https://gist.github.com/gkostadinov/2c53453eda32c6730acc64e9784a9c95

Replace them with the ones in your project. Once you have replaced them, open ImaggaRouter.swift and replace <YOUR_AUTH_TOKEN_HERE> with the authorization string found in your Imagga user dashboard here: https://imagga.com/profile/dashboard

Hope this helps!

Thanks,
Georgi

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!