iOS SDK example: Access Token revoked after single use?

Noob here. I’m trying to connect to my Photon using the provided iOS SDK example file.

1. Login to cloud works fine, console returns:

2015-11-24 20:37:05.401 Spark-SDK[59478:1709413] Logged in to cloud
Access Token: XXXXXXXXXXXXXXXXXXX

Works, great.

2. Next I’m trying to connect to my device using the Test Sequence-button:

2015-11-24 20:37:11.809 Spark-SDK[59478:1709413] MyDevice first Variable is called (null) and is from type (null)
2015-11-24 20:37:11.810 Spark-SDK[59478:1709413] MyDevice first Function is called (null)
2015-11-24 20:37:12.350 Spark-SDK[59478:1709413] Logged in to cloud
2015-11-24 20:37:12.678 Spark-SDK[59478:1709413] (
    "<SparkDevice XXXXXXXXXX, type: Photon, id: XXXXXXXXXX, name: XXXXXXXX, connected: true, variables: {\n}, functions: (\n), version: (null), requires update: false, last app: (null), last heard: 2015-11-24 19:37:09 +0000>"
)

I guess that’s fine as well, but…

3. When clicking on it again - or restarting the app for that matter -, the console will return the following, every time:

2015-11-24 20:37:15.227 Spark-SDK[59478:1709413] MyDevice first Variable is called (null) and is from type (null)
2015-11-24 20:37:15.227 Spark-SDK[59478:1709413] MyDevice first Function is called (null)
2015-11-24 20:37:15.611 Spark-SDK[59478:1709413] Logged in to cloud
2015-11-24 20:37:15.648 Spark-SDK[59478:1709413] ! getDevice https://api.particle.io/v1/devices/28001e000e47343432313031 Failed (status code 401): {
    error = "invalid_token";
    "error_description" = "The access token provided is invalid.";
}

4. Only way to resolve this problem is to manually reset the Access Token via the web IDE.

Now I’m wondering: Do Access Tokens expire after a single use? Can’t be, right? So, is there something off with my setup? oO

Thanks.

@ido should be able to help here.

Access token will expire in 90 days (i think that’s the default) so you might want to try with another access token.

1 Like

Thanks, @kennethlimcp!

Tried it several times with different tokens.

All of them only worked once - or at least, that’s what XCode’s console told me. Maybe the iOS example code is buggy or not up-to-date? Idk :confused:

Is it possible you’re “losing” the token inbetween the two runs of the app? so your second call contains a null/empty token? log the access token that you use before hitting the API, see if you got a bug there.

They don’t expire after single use ofcourse.

BTW, I recommend posting iOS-dev-related questions here:

[quote=“ido, post:7, topic:17754”]
Is it possible you’re “losing” the token inbetween the two runs of the app?[/quote]

I don’t know, but it doesn’t seem plausible to me as I haven’t modified the iOS SDK example in any way.

[quote=“ido, post:7, topic:17754”]
so your second call contains a null/empty token?[/quote]
As posted above, it returns a error 401 “invalid_token”, not sure what that means exactly. Docs doesn’t go into it any further.

[quote=“ido, post:7, topic:17754”]
log the access token that you use before hitting the API, see if you got a bug there.[/quote]
I’ll try that. :slight_smile:

I have a similar problem.
When I log the [SparkCloud ShareInstance].accessToken it’s equal to null

How do I prevent “lossing” the token in between the two runs?

Did you successfully login but session is not saved between two app runs?