|
Lucas Bakalian - 2014-05-14 10:16:50
Dear Mr Lemos,
First thank you for this incredible library, I am a beginner in oauth development. I succeeded in using your example printing the user info after haven authenticated on fitbit.com
But the same script doesn't work in a prompt.
Here is the situation:
I have stored the access_token and access_token_secret in hard in my code.
When I run login_with_fitbit.php in my browser it works but not when I do in my terminal > php login_with_fitbit.php.
It says that i do not have credential and server authorization.
I need to do this because my website will make api calls on the user behalf every day in order to analyze the data ( as a daemon and then store the data in a database );
I'm just asking for indications not global solution ;
Cordialy
Lucas Bak
Manuel Lemos - 2014-05-14 10:27:02 - In reply to message 1 from Lucas Bakalian
If you set the token variables manually, do not call the process function, or else it will attempt to restart the authorization process.
Lucas Bakalian - 2014-05-14 12:36:11 - In reply to message 2 from Manuel Lemos
thanks for your reply,
I have removed the process function and let the initialize() one;
then, I call directly callAPI().
It's the right way isn't it ?
Because I have succeeded in "var_dumping" the response in my terminal.
So I will start with this to build my web site and daemons scripts
Thank you
Cordially,
Lucas Bakalian
Manuel Lemos - 2014-05-14 19:08:51 - In reply to message 3 from Lucas Bakalian
Yes, you only need to call the process function during the authorization process. So you only need to call it again if the token expires or becomes invalid for some reason.
Lucas Bakalian - 2014-05-14 19:21:00 - In reply to message 4 from Manuel Lemos
Thank you,
Indeed it works great !
Now I can focus on parsing the response in other scripts or to populate the database with access token and users data.
From what I have seen, in the fitbit api they ask for the user id in the url, But We do not need it because I have put directly in the variable $client->access_token and $client->access_token_secret their respective values ( linked to my fitbit test account ) and I have succeeded in retrieving the data.
So is it useful ?
And if it is,
Is their anyway to get it with the Oauth class and variables ? I did no see it in the documentation .
Cordially,
Lucas Bakalian
Manuel Lemos - 2014-05-14 21:55:51 - In reply to message 5 from Lucas Bakalian
From what I could gather if you want to refer to the current authorized user you can use just - . For instance in the example that comes with the class, it uses the following API URL.
api.fitbit.com/1/user/-/profile.jso ...
Other than that, this API call returns a object with a member named encodedId that is your user id.
$user->user->encodedId
Lucas Bakalian - 2014-05-15 11:20:22 - In reply to message 1 from Lucas Bakalian
Okay I understand more deeply how it works;
Evrything works as you said, And I've noticed that when the user re connects it self on my website ( me with the fitbit test account ) the tokens expires & fitbit returns a new one.
(I've solved this issue which checking in my database)
But if not the access token will stay identical.
I'am mistaking ?
Cordialy,
Lucas Bakalian
Manuel Lemos - 2014-05-15 20:58:06 - In reply to message 7 from Lucas Bakalian
If a token expires it can be renewed only if you keep the refresh token.
If for some reason it fails, you need to prompt the user again to get a new token.
Lucas Bakalian - 2014-05-19 09:13:17 - In reply to message 8 from Manuel Lemos
Thank you for all your responses,
They have been very useful for my project.
Everything works great, I have waiting for 2 days to see if my script would still work and it's the case.
While the token have not expired, they still work, and for them to expire , the user has to re go through connection process. And for this case, my website re update the token, so that's okay.
Thank you,
Cordially;
Lucas Bakalian
|