I am trying to connect to the arduino cloud api via app, but I’m getting constant errors.
The errors that I get: Line 17: Extra arguments at positions #2, #3 in call
Line 22: Missing argument for parameter ‘connectionHandler’ in call
Line 28: Expressions are not allowed at the top level
This is the code that I’ve tried
import OAuthSwift
import Foundation
class ArduinoCloudAPI {
private let oauthswift = OAuth2Swift(
consumerKey: "26q9AmEJbbnsuXCFdg2lnWfuZ8i8Vvtq",
consumerSecret: "fcHugaFl9CAKSD8hgAYqdkD0rsCKKiC0ggEJboF9EQhHm7xsmBtsJl1Tzzk5dkti",
authorizeUrl: "",
accessTokenUrl: "https://api2.arduino.cc/iot/v1/clients/token",
responseType: "token"
)
func authenticateAndFetchProperties(thingId: String) {
oauthswift.client.credential.oauthToken = "your_saved_access_token" // If you already have a token saved
let propertiesUrl = "https://api2.arduino.cc/iot/v1/things/(thingId)/properties"
oauthswift.client.get(propertiesUrl, success: { response in
let dataString = response.string ?? "Failed to get data"
print(dataString)
}, failure: { error in
print(error.localizedDescription)
})
}
}
// Usage
let arduinoAPI = ArduinoCloudAPI()
arduinoAPI.authenticateAndFetchProperties(thingId: "9224968a-5263-4f3a-b552-94a2f3dfa69e")