iOS apps that worked 30 minutes ago are no longer working. The problem seems to be retrieving the access token. My Photons are still online and working, and I can call functions from the CLI, but not from my apps. If I call a function from my app, I get an "Invalid_token" error message. Also, I can't list my access tokens, even though I know I have at least one which I can see in Build. This is the code I use to list them,
func listAccessTokens() {
let url = NSURL(string: "https://api.particle.io/v1/access_tokens")
let request = NSMutableURLRequest(URL: url!, cachePolicy: .ReloadIgnoringCacheData, timeoutInterval: 10)
request.HTTPMethod = "GET"
let userAndPassword = userName + ":" + password
print("\(userName) \(password)")
let plainData = userAndPassword.dataUsingEncoding(NSUTF8StringEncoding)
let base64String = plainData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
request.setValue("Basic " + base64String, forHTTPHeaderField: "Authorization")
session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request) { (data, response, taskError) -> Void in
if (taskError == nil) {
do {
if let tokenArray = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as? NSArray {
print(tokenArray)
}else{
print("tokenArray was nil")
}
} catch let jsonError as NSError {
print(jsonError.localizedDescription)
}
}else{
print("taskError from executeFunction func is: \(taskError!.localizedDescription)")
}
}
dataTask.resume()
}
The result of calling this function is "tokenArray was nil". This code worked fine last night, and for many months before; it hasn't been changed recently. If I put in a statement to print out the data (after converting it to a string) before doing the JSON deserialization, then I get this output:
data string is: {
"ok": false,
"errors": [
{}
]
}
After Edit: I also tried to retrieve my access tokens using the CLI, using "particle token list" (btw, is this documented anywhere? I got it from the forum). The results of that look similar to what I get with my app,
RDM-iMac:~ ricdelmar$ particle token list
Checking with the cloud...
? Using account rdelmar@comcast.net
Please enter your password: *************
error listing tokens: [object Object]
Error listing access tokens [ {} ]
Please make sure you're online and logged in.
[ {} ]