|
![Picture of peter addy Picture of peter addy](/graphics/unknown.gif) peter addy - 2016-04-13 20:48:16
Using Fitbit2, I have authenticated several users. I can sucessfully pull activity data from one user at a time. I now want to pull activity data for all authenticated users at once. I created an array of users, and perform a foreach loop through the array to create a new mysqli_oauth_client_class and the rest of the script. The first user in the array works as expected: I set the user, call the API, finalize, and exit. My script then loops to the second user in the array, and stops working. The error is "it was not yet established an OAuth session" from database_oauth_client.php. Currently everything related to the mysqli_oauth_client class is within the foreach loop. I suspect that parts of the class should be before the loop, established only once, while other parts must be within the loop, established for each user. Is this correct? If so, which parts of the class belong before and inside the loop? My current script is organized like this:
<?php
// requirements
require('http.php');
require('oauth_client.php');
require('database_oauth_client.php');
require('mysqli_oauth_client.php');
// developer config variables
$redirect_uri = 'xxx';
$client_id = 'yyy';
$client_secret = 'zzz';
// array of authenticated users
$array = array();
// loop through array
for each ($array as $user) {
$client = new mysqli_oauth_client_class;
$client->user = $user;
$client->server = 'Fitbit2';
// class continues
if($client->exit)
exit;
if($success)
{
echo '<br>success for '.$user;
}
}
echo '<br>end of file';
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2016-04-13 23:30:45 - In reply to message 1 from peter addy
The SetUser function is just for calling when the OAuth token is retrieved for the first time.
For performing calls on behalf of that user when he is offline, you just set the user variable, so the class finds the OAuth token values in your database.
![Picture of peter addy Picture of peter addy](/graphics/unknown.gif) peter addy - 2016-04-14 12:53:43 - In reply to message 2 from Manuel Lemos
I have both
$client->user = $user;
before initialize and
$client->SetUser($user);
after initialize, both within the foreach loop. When I set the user variable the first time the class works perfectly, but it seems I cannot set the user variable a second time within the same script. Why might this be? Do you have any ideas on where to look? Finalize unsets the user at the end of the script, correct?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2016-04-14 20:05:19 - In reply to message 3 from peter addy
The SetUser call is just to tell the class that the OAuth token retrieved from the server is for that user, so it creates a database records that associates the token with the user. Do not set the user class variable here. After that you should not call the SetUser function anymore.
When you just want to call the API with the previously obtained token, you should just set the user variable first, so the class finds the token in the database.
![Picture of Thibault Mouche Picture of Thibault Mouche](/graphics/unknown.gif) Thibault Mouche - 2016-09-28 01:22:58 - In reply to message 3 from peter addy
Hi Peter,
I have the same issue, did you find an answer to the question?
|